Guest User

Untitled

a guest
Jun 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. system("date \"+%m/%d/%y %H:%M\" | md5sum | sed s/\" -\"/\"\"/ > FirstDate");
  4.  
  5. #Open FirstDate for input
  6. open(IN,"FirstDate");
  7. #Read the string into $Date
  8. $Date=<IN>;
  9. #Close the file
  10. close(IN);
  11.  
  12. #Repeat for the Key
  13. open(IN,"Key");
  14. $KEYL=<IN>;
  15. close(IN);
  16.  
  17. print "DateMD5 \n$Date\n";
  18. print "KEYMD5 \n$KEYL\n";
  19.  
  20. #MD5 Subroutines
  21. sub md5_unpack{ unpack "H*", shift }
  22. sub md5_pack { pack "H*", shift }
  23.  
  24. #print "MD5Pack KEYL\n";
  25. #print md5_pack($KEYL);
  26. #print "\nMD5Pack SD\n";
  27. #print md5_pack($Date);
  28.  
  29. #Pack both Key and Date then Xor, then Unpack back to MD5
  30. $xor = md5_unpack md5_pack($KEYL) ^ md5_pack($Date);
  31.  
  32. #print "\nPacked MD5 XOR\n";
  33. #print md5_pack($KEYL) ^ md5_pack($Date);
  34.  
  35. #Chop off the last two Zeros left over from md5_upack
  36. chop($xor);
  37. chop($xor);
  38.  
  39. print "\nMD5 Unpacked XOR\n";
  40. print $xor;
  41.  
  42.  
  43. #Write our XOR result to a file
  44. open(OUT,">MD5This");
  45. print OUT $xor;
  46. close(OUT);
  47.  
  48. #MD5 the the XOR String, store result in itself but first strip all text but the checksum.
  49. system("md5sum MD5This|sed s/\" MD5This\"/\"\"/> MD5This");
  50.  
  51. #Read the MD5'd XOR string back into $xor
  52. open(IN, "MD5This");
  53. $xor=<IN>;
  54. close(IN);
  55.  
  56. print "\nMD5'd XOR Result\n";
  57. print $xor;
  58.  
  59. #Convert $xor into an array.
  60. @xor = $xor;
  61. my @splits;
  62. my @splits2;
  63.  
  64. #Split @xor at every 4th character, into seperate array entries
  65. foreach my $keyline (@xor)
  66. {
  67. @splits = $keyline =~ /(.{1,4})/g;
  68. }
  69.  
  70. #Open knockd.conf
  71. open(OUT, ">knockd.conf");
  72.  
  73. #Print basic knockd information
  74. print OUT "[options]\nlogfile = /var/log/knockd.log\n";
  75.  
  76. #For each 4 characters we split earlier, convert them to Decimal. This gives ports from 0 - 65535 from 0000 - FFFF
  77. foreach my $test (@splits)
  78. {
  79. push(@splits2, hex($test));
  80. }
  81.  
  82. #Up to 15 Scripts in Knockd.conf
  83. #Print out the ports and the argument to pass knockScript
  84. for ($count=1;$count<15;$count++)
  85. {
  86. print OUT "[knock$count]\nsequence = ";
  87. print OUT "$count,$splits2[0],$splits2[1],$splits2[2],$splits2[3],$splits2[4],$splits2[5],$splits2[6],$splits2[7]\n";
  88. print OUT "seq_timeout = 10\ntcpflags = syn\ncommand = ./knockScript $count %IP%\n";
  89. }
  90.  
  91. close(OUT);
  92.  
  93. print "\n\n";
  94.  
  95. #Delete Temp Files
  96. system("rm FirstDate");
  97. system("rm MD5This");
Add Comment
Please, Sign In to add comment