1

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

OKIS
  • 53
  • 1
  • 8
  • 2
    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 Feb 07 '21 at 13:00
  • @mediocrevegetable1 I change push. Now "push dword str". In the internet used "push dword str". I use linux x86 – OKIS Feb 07 '21 at 13:10
  • @mediocrevegetable1 The error remains. Does not display information – OKIS Feb 07 '21 at 13:10
  • I see. I'm not using to using `printf` in NASM, so I don't want to give any further advice which could be incorrect and could potentially cause more issues. – mediocrevegetable1 Feb 07 '21 at 13:15
  • 3
    **x86 doesn't mean 86-bit**. There are only 16, 32 and 64-bit x86 – phuclv Feb 07 '21 at 14:41
  • @phuclv I had mistakes ;) Thank you for correction :) – OKIS Feb 07 '21 at 15:38
  • 4
    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 Feb 07 '21 at 15:40
  • @MargaretBloom Thank you. Say me please, how you understand where problem. This is exp or you have useful book? – OKIS Feb 07 '21 at 16:33
  • Make sure to understand everything you wrote in the source code. Why it's done this way and not this other one. For example, what the square brackets do and what a pointer is. Then familiarize yourself with a debugger, it will show you the memory addresses and values involved, making some mistakes obvious. – Margaret Bloom Feb 07 '21 at 17:00
  • @Oleg: in this case, the fact that `printf "%s"` takes a pointer arg means that pushing 4 bytes of ASCII characters is certainly going to be wrong. And yes, `uname()` fills a struct of `char[]` arrays, so the buffer contents are ASCII bytes, not pointers. As Margaret said, using a debugger will make it clear what value is in memory at `dword [uname_res]`, so you can just check whether it's a valid pointer or not. – Peter Cordes Feb 07 '21 at 18:38
  • I wrote code for linux x86. Look it here (maybe will be useful) https://github.com/OlegInfoSecurity/cpu_name https://github.com/OlegInfoSecurity/cpuid – OKIS Feb 24 '21 at 05:13

1 Answers1

0

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.

OKIS
  • 53
  • 1
  • 8
  • 1
    It's better to have answers here on the site, instead of linked. Can you write an explanation of what the problem was, with an example of working code? – Nate Eldredge Feb 24 '21 at 05:29