เมื่อเราใช้ ASP เพื่อเชื่อมต่อกับฐานข้อมูลเพื่อพัฒนาแอปพลิเคชันเราอาจพบกับสถานการณ์ที่ฐานข้อมูล ASP ถูกแขวนไว้กับโทรจันในบทความนี้เราจะแนะนำวิธีการเขียนโปรแกรมเมื่อฐานข้อมูล ASP ถูกแขวนด้วยโทรจัน จะเป็นประโยชน์กับคุณ
ในบทความนี้เราแนะนำรายละเอียดวิธีการเขียนโปรแกรมของการแก้ปัญหาโดยละเอียดของโทรจันที่ถูกแขวนคอโดยฐานข้อมูล ASP
ขั้นตอนแรก:
ทำการสำรองข้อมูลสำหรับฐานข้อมูลที่มีอยู่
ขั้นตอนที่ 2:
เรียกใช้ไฟล์ ASP ต่อไปนี้เพื่อให้สามารถลบ Trojans JS ในฐานข้อมูลได้:
หมายเหตุ: ฉันเขียนมันเอง
'ใส่เนื้อหา JS Trojan ที่นี่: โปรดอย่าลืมเปลี่ยนเป็นเนื้อหา JS Trojan ในฐานข้อมูลของคุณเอง
- <!-#includit file = conn.asp->
- -
- Server.scriptTimeOut = 180SetRstSchema = conn.openschema (20)
- k = 1
- dountilrstschema.eof 'traversal ของตารางฐานข้อมูล
- ifrstschema (table_type) = tablethen
- response.writek &. <fontcolor = red> <b> & rstschema (table_name) & </b> </font>: 'แสดงชื่อตาราง setrs = server.createObject (adodb.recordset)
- sql = select*จาก [& rstschema (table_name) &]
- Rs.Opensql, Conn, 1,3fori = 0tors.fields.count-1'transfer ฟิลด์ ifint (rs (i) .type) = 129
- Orint (RS (i) .Type) = 130Orint (RS (i) .Type) = 200Orint (RS (i) .Type) = 201Orint (RS (i) .Type) = 202Orint (RS (i) .Type) = 203 จากนั้น 'ฟิลด์การประมวลผลเท่านั้นที่มีประเภทอักขระประเภทฟิลด์
- conn.execute (อัปเดต [& rstschema (table_name) &] set & rs (i) .name & = แทนที่ (cast (& rs (i) .name &
- Asvarchar (8000)), 'ใส่เนื้อหา JS Trojan ที่นี่', '')) Response.Writers (i) .name && rs (i) .Type & 'แสดงชื่อฟิลด์ที่ดำเนินการ
- endif
- ต่อไป
- Response.write <br>
- endif
- rstschema.movenext
- kk = k+1
- วง
- Response.write การดำเนินการสำเร็จ
- -
หากมีตารางฐานข้อมูลจำนวนมากโครงสร้างฐานข้อมูล Traversal ด้านบนจะหยุดโดย IIS ก่อนที่จะดำเนินการ ในเวลานี้คุณสามารถ:
ถ้า rstschema (table_type) = ตารางจากนั้น
ช่วงของค่า k ถูกเพิ่มอย่างเหมาะสมเช่น:
ถ้า rstschema (table_type) = ตาราง k> 10 และ k <20 แล้ว
ด้วยวิธีนี้มีเพียง 9 ตารางเท่านั้นที่ใช้งานได้ในแต่ละครั้ง
ขั้นตอนที่ 3:
ตามคุณสมบัติของการฉีด JS ฐานข้อมูล (ซึ่งจะรวมถึงอักขระเช่น http: //) ใส่รหัสต่อไปนี้ใน conn.asp:
- FunctionCheAck_SQLJS () 'ป้องกันการเชื่อมโยงภายนอกฐานข้อมูลการฉีด JS: จริงคือการค้นพบการฉีดลิงค์ภายนอก JS
- dimf_post, f_get
- check_sqljs = false
- ifrequest.form <> จากนั้น 'การตรวจจับ foreachf_postinrequest.formif (instr (lcase (request.form (f_post)),
- <สคริปต์) <> 0orinstr (lcase (request.form (f_post)), </script>) <> 0)
- Andinstr (lcase (request.form (f_post)), http: //) <> 0 แล้ว
- check_sqljs = true
- ออกจาก
- endif
- ต่อไป
- endif
- ifrequest.querystring <> thenequerystring ตรวจจับในการส่ง foreachf_getinrequest.querystring
- if (instr (lcase (request.form (f_get)), <สคริปต์) <> 0orinstr (lcase (request.form (f_get)), </script>) <> 0)
- Andinstr (lcase (request.form (f_get)), http: //) <> 0 แล้ว
- check_sqljs = true
- ออกจาก
- endif
- ต่อไป
- endif
- endfunction
- FunctionCheckDataFrom () 'ตรวจสอบแหล่งข้อมูลที่ส่งข้อมูล: True ถูกส่งสำหรับข้อมูลจากภายนอกเว็บไซต์
- checkDataFrom = true
- server_v1 = cstr (request.serverVariables (http_referer)) server_v2 = cstr (request.serverVariables (server_name))
- ifmid (server_v1,8, len (server_v2)) <> server_v2then
- checkDataFrom = false
- endif
- endfunction
- ifcheack_sqljsorcheckdatafromthen
- Response.write <scriptLanguage = JavaScript> การแจ้งเตือน ('การดำเนินการเป็นสิ่งต้องห้ามดำเนินการผิดกฎหมาย'); </script> response.end ()
- endif
ทั้งหมดนี้เกี่ยวกับวิธีการเขียนโปรแกรมเมื่อฐานข้อมูล ASP ถูกแขวนไว้กับโทรจัน