Building a Web Server

第一题

题目描述说的很明白

hacker@building-a-web-server-level-1:/challenge$ ./run 
===== Welcome to Building a Web Server! =====
In this series of challenges, you will be writing assembly to interact with your environment, and ultimately build a web server
In this challenge you will exit a program.

Usage: `/challenge/run <path_to_web_server>`

$ cat server.s
.intel_syntax noprefix
.globl _start

.section .text

_start:
    mov rdi, 0
    mov rax, 60     # SYS_exit
    syscall

.section .data

$ as -o server.o server.s && ld -o server server.o

$ strace ./server
execve("./server", ["./server"], 0x7ffccb8c6480 /* 17 vars */) = 0
exit(0)                                 = ?
+++ exited with 0 +++

$ /challenge/run ./server

无非创建文件,按照它描述的指令一步一步写出来。

第二题

本来很不理解到底干嘛,看了视频才知道,是用汇编调用一次socket,然后调用exit

.intel_syntax noprefix
.global _start

.section .text

_start:
    #2,1,0
    mov rdi , 2
    mov rsi , 1
    mov rdx , 0
    mov rax , 0x29 #SYS_socket
    syscall

    mov rdi , 0
    mov rax , 60 #SYS_exit
    syscall 

.section .data

然后还是编译,执行。
关键是:

[] socket(AF_INET, SOCK_STREAM, IPPROTO_IP) = 3
[] exit(0) 

当然,我们自己写的socket,肯定就是3,因为0,1,2,系统给占据了。
然后就是个退出。

你可能感兴趣的:(服务器,linux,运维)