Nytro Posted June 10, 2011 Report Posted June 10, 2011 [Linux x86 NASM] Open, Read & Write syscalls section .bssbuffer: resb 2048 ; A 2 KB byte buffer used for readsection .databuflen: dw 2048 ; Size of our buffer to be used for readsection .textglobal _start_start:; open(char *path, int flags, mode_t mode);; Get our command line arguments.pop ebx ; argcpop ebx ; argv[0] (executable name)pop ebx ; argv[1] (desired file name)mov eax, 0x05 ; syscall number for openxor ecx, ecx ; O_RDONLY = 0xor edx, edx ; Mode is ignored when O_CREAT isn't specifiedint 0x80 ; Call the kerneltest eax, eax ; Check the output of open()jns file_read ; If the sign flag is set (positive) we can begin reading the file; = If the output is negative, then open failed. So we should exitexit:mov eax, 0x01 ; 0x01 = syscall for exitxor ebx, ebx ; makes ebx technically set to zeroint 0x80; = Begin reading the filefile_read:; read(int fd, void *buf, size_t count);mov ebx, eax ; Move our file descriptor into ebxmov eax, 0x03 ; syscall for read = 3mov ecx, buffer ; Our 2kb byte buffermov edx, buflen ; The size of our bufferint 0x80test eax, eax ; Check for errors / EOFjz file_out ; If EOF, then write our buffer out.js exit ; If read failed, we exit.; No error or EOF. Keep reading .file_out:; write(int fd, void *buf, size_t count);mov edx, eax ; read returns amount of bytes readmov eax, 0x04 ; syscall write = 4mov ebx, 0x01 ; STDOUT = 1mov ecx, buffer ; Move our buffer into the argumentsint 0x80jmp exit ; All done Sursa: [Linux x86 NASM] Open, Read & Write syscalls - r00tsecurity Quote