1
votes

I only study assembler (nasm) and have more question. For example i want make asm code that get info about operating system. I use linux 86 bit. In a code i use syscall uname. In a browser have more information about this syscall and code. I found this link:

https://github.com/hc0d3r/asm/blob/master/uname.asm

Uname syscall in buffer overflow

But i use 86 bit system. So, i tried rewrite code for my system. I understand, that in register eax i should move value of syscall (0x7a or 122) and in register ebx addres of array.

I used first link as example, but get error. So, can you help me decide this problem?

This is my main code:

extern printf

SYS_WRITE equ 4
SYS_UNAME equ 122
SYS_EXIT equ 60
STDOUT equ 1

section .data
str: db '%s',10,0
UTSNAME_SIZE equ 65
space db ' '
break_line db 0xa

section .bss
uname_res resb UTSNAME_SIZE*5

section .text
global main
main:
    mov eax, 0x7A
    mov ebx, uname_res
    int 80h


push dword [uname_res]
    push dword str
    call printf

mov eax, 1
int 80h

and I got this error:

segmentation error (memory dump made)

This mistake on printf. Sorry for my crooked english

1
I'm not used to pushing arguments to the stack, but have you tried push str instead of push dword [str]? Also, by 86 bit do you mean x86?mediocrevegetable1
@mediocrevegetable1 I change push. Now "push dword str". In the internet used "push dword str". I use linux x86OKIS
@mediocrevegetable1 The error remains. Does not display informationOKIS
x86 doesn't mean 86-bit. There are only 16, 32 and 64-bit x86phuclv
Didn't recall what syscall 0x7a does, but push dword [uname_res] is probably wrong, you probably want push uname_res. Also, familiarize yourself with gdb, radare2, or any debugger, they will help you shed some light on the crashes.Margaret Bloom

1 Answers

0
votes

I wrote code for linux x86. Look it here (maybe will be useful)

https://github.com/OlegInfoSecurity/uname_x86

This error occurred when i output (print) info. I changed code for output info and program is work.