rovinbhandari / ftp Goto Github PK
View Code? Open in Web Editor NEWImplementation of a simple FTP client and server
Implementation of a simple FTP client and server
在命令字符串解析函数中,struct command* userinputtocommand(char s[LENUSERINPUT]),for语句语法错误!这个错编译器不会报错,找了好久终于找到了。
另:我把它改了改,可以在win下运行啦
Using the prepared patch file reproduce.patch for better illustration.
patch -p1 < reproduce.patch
Compile
make
Start the server
./bin/server/server_ftp.out
Start the client to establish the connection and exit immediately
timeout 1s ./bin/client/client_ftp.out
Then, the server will crash with AddressSanitizer report:
=================================================================
==1199805==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 512 byte(s) in 1 object(s) allocated from:
#0 0x55ec05154f7e in __interceptor_malloc (/root/projects/FTP/bin/server/server_ftp.out+0xa6f7e) (BuildId: 66b4d91f9c39c73e3399c16f9d667ddf369a1250)
#1 0x55ec05192071 in serve_client /root/projects/FTP/server_ftp.c:53:41
#2 0x55ec05191e28 in main /root/projects/FTP/server_ftp.c:40:2
#3 0x7f6b1e895d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09) (BuildId: b503275bf9fee51581fdceef97533b194035b4f7)
Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x55ec05154f7e in __interceptor_malloc (/root/projects/FTP/bin/server/server_ftp.out+0xa6f7e) (BuildId: 66b4d91f9c39c73e3399c16f9d667ddf369a1250)
#1 0x55ec0518f917 in client_info_alloc /root/projects/FTP/server_ftp_functions.c:7:49
#2 0x55ec05191e15 in main /root/projects/FTP/server_ftp.c:39:27
#3 0x7f6b1e895d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09) (BuildId: b503275bf9fee51581fdceef97533b194035b4f7)
SUMMARY: AddressSanitizer: 520 byte(s) leaked in 2 allocation(s).
The server use function serve_client
to handle each connection from the client:
Lines 32 to 41 in 96c1a35
In the function serve_client
, the memory allocated via malloc
is never freed, causing memory leak.
Line 53 in 96c1a35
This bug can cause denial-of-service.
struct command* cmd = (struct command*) malloc(sizeof(struct command));
when use malloc
, we should use free
, and also should free npaths
make
./bin/server/server_ftp.out
./bin/client/client_ftp.out
CLIENT=> FTP Client started up. Attempting communication with server @ 127.0.0.1:8487...
> ls
FILE: Makefile
FILE: TODO
DIR: .git
FILE: client_ftp_functions.c
FILE: server_ftp_functions.c
DIR: ..
FILE: client_ftp.h
FILE: commons.c
FILE: file_transfer_functions.c
FILE: server_ftp.h
FILE: commons.h
FILE: server_ftp.c
DIR: bin
FILE: README
DIR: .
FILE: .gitignore
DIR: obj
FILE: file_transfer_functions.h
FILE: .vimrc.custom.FTP
FILE: client_ftp.c
4.2 Then try to get a file that does not exist (file_not_exist
)
> get file_not_exist
File found; processing
1 data packet(s) received.
0 byte(s) written.
4.3 List the file after the get
command
> ls
FILE: Makefile
FILE: TODO
DIR: .git
FILE: client_ftp_functions.c
FILE: file_not_exist
FILE: server_ftp_functions.c
DIR: ..
FILE: client_ftp.h
FILE: commons.c
FILE: file_transfer_functions.c
FILE: server_ftp.h
FILE: commons.h
FILE: server_ftp.c
DIR: bin
FILE: README
DIR: .
FILE: .gitignore
DIR: obj
FILE: file_transfer_functions.h
FILE: .vimrc.custom.FTP
FILE: client_ftp.c
>
We can see that file_not_exist
is created.
Lines 51 to 69 in 96c1a35
command_get
function should first check the existence of the file to transfer.what the compile tutorial please ! and what the best tool for compile and build ?!
By using the cd .. command, an attacker can traverse to the root directory, and from there into any directory the FTP server has read access to. By combining this with the get and put commands, arbitrary files can be downloaded from, or uploaded to, the target.
You malloc
ate a chunk for each request but don't free it. See below:
struct packet* data = (struct packet*) malloc(size_packet);
It never free
s it though.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.