flat assembler
Message board for the users of flat assembler.

Index > Linux > [solved] Problem with mkdir syscall

Author
Thread Post new topic Reply to topic
Potato



Joined: 18 Apr 2020
Posts: 11
Potato 21 Apr 2020, 08:55
Ok, I tap out, I can't find an example or information on this.

What I am trying to do:
create a directory called test

Info I found so far,

https://filippo.io/linux-syscall-table/

this website seemed to have a list of what registers I needed to update before I made the syscall and gave the relivant number I needed (83).

Other than that have not really found anything usefull.

This was my first atempt, I am thinking that it needs to be a pointer to the string. Other thoughts were perhaps it needed a terminator (meh - clutching at straws).

Perhaps there is a need for a chmod type command before the directory gets created?

My next plan is to write a simple program in c and pick apart the output to figure how its done.

There has to be a sequence of syscalls to make these directory and file operations happen.

Code:
format ELF64 executable 3
segment readable executable
entry   main

main:
        mov rax,83
        mov rdi,namen
        syscall
        call exit
exit:   
        xor rdi,rdi
        mov rax,60
        syscall

segment readable writeable
namen   db 'test',0
    
Post 21 Apr 2020, 08:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 21 Apr 2020, 09:37
The syscall for mkdir also needs a mode parameter.
Code:
SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode)    
Post 21 Apr 2020, 09:37
View user's profile Send private message Visit poster's website Reply with quote
Potato



Joined: 18 Apr 2020
Posts: 11
Potato 21 Apr 2020, 10:33
revolution wrote:
The syscall for mkdir also needs a mode parameter.
Code:
SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode)    


Ok, so RSI needs a value - am going to assume its 511/777

Code:
main:
        mov rax,83
        mov rdi,namen
        mov rsi,777o
        syscall
        call exit

    


this still does not work. hmm... Sad
Post 21 Apr 2020, 10:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 21 Apr 2020, 10:36
RAX has a return value. It might tell you what went wrong.
Post 21 Apr 2020, 10:36
View user's profile Send private message Visit poster's website Reply with quote
Potato



Joined: 18 Apr 2020
Posts: 11
Potato 21 Apr 2020, 10:56
revolution wrote:
RAX has a return value. It might tell you what went wrong.


holy moly, it worked! lol I must have not been compiling the program properly, when i used the debuger, I steped through a few times and all the exit codes were 00h so I was thinking 'hmmm thats saying everything is fantastic'.. I looked at the directory and sure enough test was there.. Laughing thanks for the help.

Code:
format ELF64 executable 3
segment readable executable
entry   main

main:
        mov rax,83
        mov rdi,namen
        mov rsi,0
        syscall
        call exit
exit:   
        xor rdi,rdi
        mov rax,60
        syscall

segment readable writeable
namen   db 'test',0
    


The intresting thing is that its writing the directory with root permision, when you try and access the directory as a normal user its forbiden. - scratch that I was being a Potato and was not setting the chmod correctly. Embarassed

should have been

Code:
        mov rsi,777o
    


everything works! Horray - I couldn't help myself sorry. here is a program to delete the test directory.

Code:
format ELF64 executable 3
segment readable executable
entry   main

main:
        mov rax,84
        mov rdi,namen
        syscall
        call exit
exit:   
        xor rdi,rdi
        mov rax,60
        syscall

segment readable writeable
namen   db 'test',0
    
Post 21 Apr 2020, 10:56
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.