When we use ASP to connect to database to develop applications, we may encounter the situation where the ASP database is hung with a Trojan. In this article, we will introduce the programming method when the ASP database is hung with a Trojan. I hope it will be helpful to you.
In this article, we introduce in detail the programming method of the detailed solution of the Trojan hanged by ASP database. The solution is divided into the following three steps:
first step:
Make backups for existing databases.
Step 2:
Execute the following ASP file, so that the JS Trojans in the database can be removed:
Note: I wrote it myself.
'Put the JS Trojan content here: Please remember to change it to the JS Trojan content in your own database.
- <!--#includefile=conn.asp-->
- <%
- Server.ScriptTimeOut=180SetrstSchema=conn.OpenSchema(20)
- k=1
- DoUntilrstSchema.EOF' traversal of database tables
- IfrstSchema(TABLE_TYPE)=TABLEThen
- response.writeK&.<fontcolor=red><b>&rstSchema(TABLE_NAME)&</b></font>:'Show table name Setrs=Server.CreateObject(ADODB.Recordset)
- sql=select*from[&rstSchema(TABLE_NAME)&]
- rs.opensql,conn,1,3Fori=0tors.fields.count-1'Transfer field 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)= 203Then' only processing fields with field type character type
- conn.execute(update[&rstSchema(TABLE_NAME)&]set&rs(i).name&=replace(cast(&rs(i).name&
- asvarchar(8000)),'Put JS Trojan content here','')) response.writers(i).name&&rs(i).Type&' displays the executed field name.
- EndIf
- Next
- response.write<br>
- EndIf
- rstSchema.MoveNext
- kk=k+1
- Loop
- response.Write execution successfully
- %>
If there are many database tables, the above traversal database structure will be stopped by IIS before it is executed. At this time you can:
If rstSchema(TABLE_TYPE)=TABLE Then
The range of k values is appropriately added, such as:
If rstSchema(TABLE_TYPE)=TABLE k>10 and k<20 Then
In this way, only 9 tables are operated at a time.
Step 3:
According to the characteristics of database JS injection (which will include characters like http://), put the following code in conn.asp:
- FunctionCheack_Sqljs()' Prevents database external link JS injection: true is to discover external link JS injection.
- DimF_Post,F_Get
- Check_Sqljs=False
- IfRequest.Form<>Then' Detection of ForEachF_PostInRequest.FormIf(Instr(LCase(Request.Form(F_Post)),
- <script)<>0orInstr(LCase(Request.Form(F_Post)),</script>)<>0)
- andInstr(LCase(Request.Form(F_Post)), http://)<>0Then
- Check_Sqljs=True
- ExitFor
- EndIf
- Next
- EndIf
- IfRequest.QueryString<>Then'QueryString Detection on Submission ForEachF_GetInRequest.QueryString
- If(Instr(LCase(Request.Form(F_Get)),<script)<>0orInstr(LCase(Request.Form(F_Get)),</script>)<>0)
- andInstr(LCase(Request.Form(F_Get)), http://)<>0Then
- Check_Sqljs=True
- ExitFor
- EndIf
- Next
- EndIf
- EndFunction
- FunctionCheckDataFrom()'Check the data submitted source: True is submitted for data from outside the site
- 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>alert('Execution is prohibited, illegal operation.');</Script>Response.End()
- EndIf
This is all about the programming method when the ASP database is hung with a Trojan. I hope this introduction can bring you some benefits. Thank you!