Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.54 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use FileHandle;
  5. use Getopt::Long;
  6.  
  7. our ($antiptrace, $noircbacktrace, $ssl, $little_endian, $big_endian, $cc_prefix, $cc_options, $ld_options, $disable_adns, $firedns);
  8.  
  9. if(!GetOptions(
  10. "--with-antiptrace" => \$antiptrace,
  11. "--no-irc-backtrace" => \$noircbacktrace,
  12. "--little-endian" => \$little_endian,
  13. "--big-endian" => \$big_endian,
  14. "--cc-prefix:s" => \$cc_prefix,
  15. "--cc-options:s" => \$cc_options,
  16. "--ld-options:s" => \$ld_options,
  17. "--disable-adns" => \$disable_adns,
  18. "--with-ssl" => \$ssl,
  19. "--with-firedns" => \$firedns))
  20. {
  21. exit();
  22. }
  23.  
  24. my %targets;
  25.  
  26. $targets{'dynamic'} = '-Wall -Wno-non-virtual-dtor';
  27. $targets{'static'} = '-Wall -Wno-non-virtual-dtor -static -DHAVE_STATIC';
  28. $targets{'debug'} = '-DHAVE_DEBUG -g -fno-inline -pedantic -Wall -Wno-long-long -Wformat=2 -Wunused -Wno-non-virtual-dtor';
  29.  
  30. my $filelist = "
  31. class-adns.o
  32. class-adns-firedns.o
  33. class-adns-pthread.o
  34. botcmd.o
  35. class-blowfish.o
  36. class-chan-actions.o
  37. class-chan.o
  38. class-chan-gotmode.o
  39. class-comment.o
  40. class-client.o
  41. class-clone.o
  42. class-customdata.o
  43. class-ent.o
  44. class-http.o
  45. class-ignore.o
  46. class-inet.o
  47. class-idle.o
  48. class-listcmd.o
  49. class-modeq.o
  50. class-masklist.o
  51. class-offence.o
  52. class-pchar.cpp
  53. class-penal.o
  54. class-ptime.o
  55. class-fifo.o
  56. class-tcl.o
  57. class-userlist.o
  58. class-wasop.o
  59. class-update.o
  60. class-options.o
  61. class-server.o
  62. class-shitlist.o
  63. class-socks5.o
  64. config-create.o
  65. config-load.o
  66. dlsym_cast.o
  67. firedns.o
  68. firestring.o
  69. functions.o
  70. hidden-seed-functions.o
  71. inet_pton.o
  72. main.o
  73. match.o
  74. md5.o
  75. md5func.o
  76. parse-bot.o
  77. parse-botnet.o
  78. parse-ctcp.o
  79. parse-hub.o
  80. parse-irc.o
  81. parse-owner.o
  82. random.o
  83. signals.o";
  84.  
  85. my $moduleList = "control
  86. date
  87. log
  88. noautorejoin
  89. op
  90. peak
  91. peak2
  92. raw
  93. repeat
  94. spam
  95. subop
  96. uptime
  97. vctrl
  98. words";
  99.  
  100. require 'tests/test.pm';
  101. chdir('tests');
  102. print "[*] Running system check (this may take a while)\n";
  103. my $os = `uname`;
  104. $os =~ s/\n//;
  105. print "[*] Operating system: $os\n";
  106. my ($cflags, $lflags) = getGccOptions();
  107.  
  108. chdir('..');
  109.  
  110. if($antiptrace) {
  111. print "[+] Enabling antiptrace\n";
  112. $cflags .= "-DHAVE_ANTIPTRACE ";
  113. }
  114. else {
  115. print "[-] Disabling antiptrace (pass --with-antiptrace to enable)\n";
  116. }
  117.  
  118. if($noircbacktrace) {
  119. print "[-] Disabling irc backtrace\n";
  120. }
  121. else {
  122. print "[+] Enabling irc backtrace (pass --no-irc-backtrace to disable)\n";
  123. $cflags .= "-DHAVE_IRC_BACKTRACE ";
  124. }
  125.  
  126. if($ssl) {
  127. print "[+] Enabling SSL support (irc, partyline)\n";
  128. $cflags .= "-DHAVE_SSL ";
  129. $lflags .= "-lssl ";
  130. }
  131. else {
  132. print "[-] Disabling SSL support (pass --with-ssl to enable)\n";
  133. }
  134.  
  135. print "[*] Compile options: $cflags\n";
  136. print "[*] Link options: $lflags\n";
  137.  
  138. $filelist =~ tr/\n/ /;
  139.  
  140. my $ver = `cat defines.h | egrep S_VERSION | awk '{ print substr(\$3, 2, length(\$3)-2) }'`;
  141. $ver =~ s/\n//;
  142.  
  143. #
  144. # Generating makefile
  145. #
  146.  
  147. my $f = new FileHandle "> Makefile" or die 'Cannot create Makefile';
  148.  
  149. my (@arg, $i, $last, $d, $st, $out);
  150.  
  151. print "[+] Generating Makefile\n";
  152. print $f "#########################################\n";
  153. print $f "# Code generated by configure\n";
  154. print $f "#\n";
  155. print $f "# Copyright (c) 2004-2007 Grzegorz Rusin <grusin\@gmail.com>\n";
  156. print $f "# WARNING! All changes made in this file will be lost!\n";
  157. print $f "# \n\n";
  158.  
  159. print $f "list:\n";
  160. print $f "\t\@echo Available targets:\n";
  161. print $f "\t\@echo '* dynamic (prefered for most systems)'\n";
  162. print $f "\t\@echo '* static'\n";
  163. print $f "\t\@echo '* debug'\n";
  164. print $f "\t\@echo '* apidox'\n\n";
  165.  
  166. print $f "create_hidden_seed:\n";
  167. print $f "\t\@${cc_prefix}g++ -o make-hiddenseed make-hiddenseed.c && ./make-hiddenseed > hidden-seed-functions.c\n\n";
  168.  
  169. print $f "debug: create_hidden_seed\n";
  170. print $f "\t\@echo [*] Making debug\n";
  171. print $f "\t\@\$(MAKE) -f Makefile.debug\n\n";
  172.  
  173. print $f "dynamic: create_hidden_seed\n";
  174. print $f "\t\@echo [*] Making static\n";
  175. print $f "\t\@\$(MAKE) -f Makefile.static\n\n";
  176.  
  177. print $f "apidox:\n";
  178. print $f "\t\@echo [*] Generating API documentation\n";
  179. print $f "\t\@doxygen Doxyfile > docs/doxygen.log 2>&1\n\n";
  180.  
  181. print $f "\nclean:\n";
  182. print $f "\t\@rm -f *.exe *.o core psotnic-* psotnic validator *.log vgcore.* tests/a.out tests/a.exe make-hiddenseed\n\n";
  183. print $f "\t\@echo [*] Removing temporary files\n";
  184.  
  185. print $f "\ndistclean:\n";
  186. print $f "\t\@\$(MAKE) clean\n";
  187. print $f "\t\@echo [*] Removing seed.h\n";
  188. print $f "\t\@rm -f seed.h\n";
  189. print $f "\t\@rm -rf bin/* pid.* *.ul config.h Makefile Makefile.* modules/Makefile modules/plog/Makefile modules/*.so\n\n";
  190.  
  191. print $f "current:\n";
  192. print $f "\t\@echo [*] Making current source package\n";
  193. print $f "\t\@\$(MAKE) distclean\n";
  194. print $f "\t\@tar -cf ../psotnic-current.tar ../psotnic-current/\n";
  195. print $f "\t\@gzip -f9 ../psotnic-current.tar\n";
  196. print $f "\t\@echo [+] Done\n";
  197.  
  198. print $f "release:\n";
  199. print $f "\t\@echo [*] Making release source package\n";
  200. print $f "\t\@\$(MAKE) distclean\n";
  201. print $f "\t\@tar -cf ../psotnic-current.tar ../psotnic-current/\n";
  202. print $f "\t\@gzip -f9 ../psotnic-current.tar\n";
  203. print $f "\t\@echo [+] Done\n";
  204.  
  205.  
  206. $f->close;
  207.  
  208. #
  209. # Generating Makefile.$target
  210. #
  211.  
  212. if($os =~ /cygwin/i) {
  213. $out = "bin/psotnic.exe";
  214.  
  215. if($cflags =~/-DHAVE_IPV6/) {
  216. $cflags .= "-Dsocklen_t=int -fpermissive ";
  217. }
  218. $cflags .= "-DHAVE_CYGWIN ";
  219. }
  220. else {
  221. $out = "bin/psotnic";
  222. }
  223.  
  224. my ($t, @tmp);
  225.  
  226. foreach $t (keys %targets)
  227. {
  228. {
  229. $f = new FileHandle "> Makefile.$t" or die "[-] Cannot create Makefile.$t";
  230. print "[+] Generating Makefile.$t\n";
  231. print $f "#########################################\n";
  232. print $f "# Code generated by configure\n";
  233. print $f "#\n";
  234. print $f "# Copyright (c) 2003-2005 Grzegorz Rusin <grusin\@gmail.com>\n";
  235. print $f "# WARNING! All changes made in this file will be lost!\n";
  236. print $f "# \n\n";
  237.  
  238. print $f ".SUFFIXES: .o .c .cpp\n\n";
  239. print $f ".c.o:\n";
  240. print $f "\t\@echo [*] Compiling \$<\n";
  241. print $f "\t\@${cc_prefix}g++ -c \$< $targets{$t} $cflags\n\n";
  242.  
  243. print $f ".cpp.o:\n";
  244. print $f "\t\@echo [*] Compiling \$<\n";
  245. print $f "\t\@${cc_prefix}g++ -c \$< $targets{$t} $cflags\n\n";
  246.  
  247. print $f ".cc.o:\n";
  248. print $f "\t\@echo [*] Compiling \$<\n";
  249. print $f "\t\@${cc_prefix}g++ -c \$< $targets{$t} $cflags\n\n";
  250.  
  251. print $f "tar: $filelist\n";
  252. print $f "\t\@echo [*] Linking\n";
  253. print $f "\t\@test -d bin || mkdir bin\n";
  254.  
  255. if($t =~ /debug|dynamic/) {
  256. print $f "\t\@${cc_prefix}g++ $filelist -o $out $targets{$t} $cflags $lflags -export-dynamic\n";
  257. }
  258. else {
  259. print $f "\t\@${cc_prefix}g++ $filelist -o $out $targets{$t} $cflags $lflags\n";
  260. }
  261.  
  262. if(!($t =~ /debug/)) {
  263. print $f "\t\@echo [*] Striping debug information\n";
  264. print $f "\t\@${cc_prefix}strip $out\n";
  265. }
  266.  
  267. print $f "\t\@echo [*] We are done\n";
  268. $f->close;
  269. }
  270.  
  271. #
  272. # Modules makefile
  273. #
  274. my $f = new FileHandle "> modules/Makefile" or die 'Cannot create modules/Makefile';
  275.  
  276. print "[+] Generating modules/Makefile\n";
  277. print $f "#########################################\n";
  278. print $f "# Code generated by configure\n";
  279. print $f "#\n";
  280. print $f "# Copyright (c) 2004-2007 Grzegorz Rusin <grusin\@gmail.com>\n";
  281. print $f "# WARNING! All changes made in this file will be lost!\n";
  282. print $f "# \n\n";
  283.  
  284. my @modules = split /\n/, $moduleList;
  285. print $f "all:";
  286. foreach (@modules)
  287.  
  288. print $f "$_:\n";
  289. print $f "\t\@echo [*] Compiling module $_\n";
  290. print $f "\t\@g++ -o $_.so $_.cpp -shared\n\n";
  291. }
  292.  
  293. print $f "clean:\n";
  294. print $f "\t\@echo [*] Cleaning up\n";
  295. print $f "\t\@rm -f *.so\n\n";
  296.  
  297. $f->close();
  298.  
  299. #
  300. # Plog makefile
  301. #
  302. my $f = new FileHandle "> modules/plog/Makefile" or die 'Cannot create plog Makefile';
  303.  
  304. print "[+] Generating modules/plog/Makefile\n";
  305. print $f "###########################################\n";
  306. print $f "# Code generated by configure\n";
  307. print $f "#\n";
  308. print $f "# Copyright (c) 2004-2007 Grzegorz Rusin <grusin\@gmail.com>\n";
  309. print $f "# WARNING: All changes made to this file will be lost!\n";
  310. print $f "#\n\n";
  311. print $f "plog:\n";
  312. print $f "\t\@echo [*] Compiling module plog\n";
  313. print $f "\t\@g++ main.cpp plog.cpp misc.cpp -o ../plog.so -shared\n";
  314. $f->close();
  315.  
  316. #
  317. # Generating random seed
  318. #
  319.  
  320. if(-f "seed.h")
  321. {
  322. print "[!] Random seed (seed.h) exists, using existing one.\n";
  323. }
  324. else
  325. {
  326. $f = new FileHandle "> seed.h";
  327. if(defined $f)
  328. {
  329. print "[+] Generating seed.h\n";
  330. print $f "/*\n";
  331. print $f " * This file contains magical seeds that will be used during encryption/decryption process.\n";
  332. print $f " * So make sure that you store it in safe place, if you loose it you wont be able to decode\n";
  333. print $f " * crypted files.\n";
  334. print $f " */\n\n";
  335. print $f "#ifndef PSOTNIC_SEED_H\n";
  336. print $f "#define PSOTNIC_SEED_H 1\n\n";
  337.  
  338. my $cfg_seed = "";
  339.  
  340. my $ul_seed = "";
  341.  
  342. for($i=0; $i<16; ++$i) {
  343. $cfg_seed .= sprintf("\\x%02x", rand(256));
  344. }
  345.  
  346. for($i=0; $i<16; ++$i) {
  347. $ul_seed .= sprintf("\\x%02x", rand(256));
  348. }
  349.  
  350. print $f "static unsigned char cfg_seed[] = \"$cfg_seed\";\n";
  351. print $f "static unsigned char ul_seed[] = \"$ul_seed\";\n\n";
  352. print $f "#endif\n";
  353.  
  354. print "[*] Random seeds for all binaries are located in seed.h\n";
  355. print "[*] Please backup seed.h when you finish compilation\n";
  356. }
  357. else
  358. {
  359. print "FATAL: Cannot create seed.h\n";
  360. die;
  361. }
  362. }
  363.  
  364. #moved to makefiles, to keep compatybility
  365. #`gcc -o make-hiddenseed make-hiddenseed.c && ./make-hiddenseed > hidden-seed-functions.c`;
  366.  
  367. #
  368. # Creating revision file my $ul_seed = "";
  369.  
  370. for($i=0; $i<16; ++$i) {
  371. $cfg_seed .= sprintf("\\x%02x", rand(256));
  372. }
  373.  
  374. for($i=0; $i<16; ++$i) {
  375. $ul_seed .= sprintf("\\x%02x", rand(256));
  376. }
  377.  
  378. print $f "static unsigned char cfg_seed[] = \"$cfg_seed\";\n";
  379. print $f "static unsigned char ul_seed[] = \"$ul_seed\";\n\n";
  380. print $f "#endif\n";
  381.  
  382. print "[*] Random seeds for all binaries are located in seed.h\n";
  383. print "[*] Please backup seed.h when you finish compilation\n";
  384. }
  385. else
  386. {
  387. print "FATAL: Cannot create seed.h\n";
  388. die;
  389. }
  390. }
  391.  
  392. #moved to makefiles, to keep compatybility
  393. #`gcc -o make-hiddenseed make-hiddenseed.c && ./make-hiddenseed > hidden-seed-functions.c`;
  394.  
  395. #
  396. # Creating revision file
  397. print "[*] Retrieving SVN revision\n";
  398.  
  399.  
  400. my $svn_entries = ".svn/entries";
  401.  
  402. sub check_svn_revision
  403. {
  404. my $f = shift;
  405.  
  406. my $x = `head -n 4 $f | tail -n 1 2>/dev/null`;
  407. $x =~ s/\n//;
  408. if(!($x =~ /^\d+$/))
  409. {
  410. $x = `head -n 4 $f | tail -1 2>/dev/null`;
  411. $x =~ s/\n//;
  412. }
  413.  
  414. if(!($x =~ /^\d+$/))
  415. {
  416. $x = 'UNKNOWN';
  417. }
  418.  
  419. return $x;
  420. }
  421.  
  422. my $svn_rev = check_svn_revision($svn_entries);
  423. if($svn_rev == 'UNKNOWN')
  424. {
  425. my $currDir = `pwd`;
  426.  
  427. if($currDir =~ /.*\/\.update-[0-9]*$/)
  428. {
  429. $svn_entries = `ls psotnic-*/.svn/entries`;
  430. $svn_entries =~ s/\n//;
  431. if($svn_entries =~ /entries/) {
  432. $svn_rev = check_svn_revision($svn_entries);
  433. }
  434. }
  435. }
  436.  
  437. $cflags .= "-DSVN_REVISION=\"$svn_rev\" ";
  438. print "[+] Done; Source Code Revision = $svn_rev\n";
  439.  
  440.  
  441. #
  442. # Generating config.h
  443. #
  444. $f = new FileHandle "> config.h";
  445. if(defined $f)
  446. {
  447. print "[+] Generating config.h\n";
  448. print $f "#ifndef PSOTNIC_CONFIG_H\n";
  449. print $f "#define PSOTNIC_CONFIG_H 1\n\n";
  450.  
  451. my @arr = split(/ /, $cflags);
  452. foreach(@arr)
  453. {
  454. if(/(-D)(.*)=(.*)/) {
  455. print $f "#ifndef $2\n";
  456. print $f "#\tdefine $2\t$3\n";
  457. print $f "#endif\n\n";
  458. }
  459. elsif(/(-D)(.*)/) {
  460. print $f "#ifndef $2\n";
  461. print $f "\t#define $2\t1\n";
  462. print $f "#endif\n\n";
  463. }
  464. }
  465. print $f "\n#endif\n";
  466. $f->close
  467. }
  468.  
  469. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement