PDA

View Full Version : Code to generate Metasploit Shellcode



JMC31337
10-30-2008, 04:42 PM
This code was taken from >> Confessions of a Penetration Tester <<
This code actually allows us to use Java converted to JavaScript to use Metasploit shellcode in Java. Knowledge of Metasploit and Java would be helpful.
============================
public class toJS {
static int LENGTH=870; //NOTE: make sure the code length matches your generated shell code
static byte shell[] = new byte[]
{
// Metasploit chell code goes here
};
public static void main(String[] args) {
String shell2 = "";
for (int i=0; i< LENGTH; i=i+2)
{
int b1 =((byte) shell[i+1] << 8) & 0x0000ff00;
b1 = b1 | ((byte) shell[i] & 0x000000ff);
String word = Integer.toHexString(b1);
if(word.length()==0)
word = "0000";
else if (word.length() ==1)
word = "000" + word;
else if( word.length() ==2 )
word = "00" + word;
else if( word.length() ==3 )
word = "0" + word;
shell2 += "%u" + word;
} System.out.println(shell2); }}
==========================