Reputation: 95
This is frustrating. I am writing a C program where I need to create a self modifying dd, i.e., the dd is capable of modifying itself on the run [ifd = open(stdin) and ofd = open (/proc/self/mem)]
When I run the following, directly in terminal, the setarch command sets the ADDR_NO_RANDOMIZE flag and a self modifying dd gets succesfully created. However, when I run it through system() it fails with an error.
system( "setarch x86_64 -R dd of=/proc/self/mem bs=1 seek=$(( 0x555555554000 + 0xa823 )) conv=notrunc 10<&0 11<&1");
Maybe I am missing something very obvious as I am not very good at shell programming.
The error is as follows:
dd: unrecognized operand ‘10’
Try 'dd --help' for more information.
Note: I have used 10 and 11 to duplicate stdin and stdout File Descriptors in my code.
Thanks a-million!
Upvotes: 0
Views: 82
Reputation: 123430
POSIX sh only guarantees support for FDs from 0 to 9.
If you need FDs higher than that, you should run your command in bash
or another shell that supports this:
system("bash -c 'setarch x86_64 -R dd of=/proc/self/mem "
"bs=1 seek=$(( SEGMENT + OFFSET )) conv=notrunc 10<&0 11<&1'");
Upvotes: 4