-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch.py
More file actions
128 lines (109 loc) · 4.4 KB
/
batch.py
File metadata and controls
128 lines (109 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import string
import random
import keyword
# 변수 설정
length = 100
hiddenlistresult = []
hiddenloclistresult = []
hiddencharlistresult = []
hiddenlist = []
hiddencharlist = []
hiddenloclist =[]
randomvar = []
file = './flag.bat'
def generate_random(length): # 배치 파일 변수 이름 랜덤 지정을 위한 함수
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' #문자들
random_str = ''.join(random.choice(letters) for _ in range(length))
while keyword.iskeyword(random_str):
random_str = ''.join(random.choice(letters) for _ in range(length))
return random_str
def generate_random_hidden(length, hidden): #배치 파일 변수 값에 문자를 집어넣기 위한 함수
if hidden.isspace():
letters = string.ascii_letters
random_str = ''.join(random.choice(letters) for _ in range(length+1))
while keyword.iskeyword(random_str):
random_str = ''.join(random.choice(letters) for _ in range(length+1))
return random_str
elif (hidden == "%" or hidden == "@" or hidden == '"' or hidden == "(" or hidden == ")" or hidden == ":"):
# or hidden == "=" or hidden == "=="
letters = string.ascii_letters
random_str = ''.join(random.choice(letters) for _ in range(length+1))
while keyword.iskeyword(random_str):
random_str = ''.join(random.choice(letters) for _ in range(length+1))
return random_str
else:
letters = string.ascii_lowercase
random_str = ''.join(random.choice(letters) for _ in range(length))
while keyword.iskeyword(random_str):
random_str = ''.join(random.choice(letters) for _ in range(length))
random_index = random.randint(0, len(random_str)-1)
new_str = random_str[:random_index] + hidden + random_str[random_index:]
return new_str
with open(file, 'r') as f:
line = f.readline()
while line:
for i in range(len(line)):
temp = line[i]
hiddencharlist.append(temp)
hidden = generate_random_hidden(length,temp)
hiddenlist.append(hidden)
hiddenloclist.append(hidden.find(temp))
line = f.readline()
zipped = list(zip(hiddenlist, hiddenloclist, hiddencharlist))
random.shuffle(zipped)
shuffledhiddenlist, shuffledhiddenloclist, shuffledhiddencharlist = zip(*zipped)
# print(shuffledhiddenlist)
# print(shuffledhiddenloclist)
# print(shuffledhiddencharlist)
for v in shuffledhiddencharlist:
if v not in hiddencharlistresult:
temp = shuffledhiddencharlist.index(v)
hiddenloclistresult.append(shuffledhiddenloclist[temp])
hiddenlistresult.append(shuffledhiddenlist[temp])
hiddencharlistresult.append(v)
randomvar.append(generate_random(length))
charhidden = dict(zip(hiddencharlistresult, hiddenlistresult))
randomhidden = dict(zip(randomvar, hiddenlistresult))
hiddenrandom = dict(zip(hiddencharlistresult, randomvar))
# print(randomhidden)
# print(res.get('e'))
# temp = res.get('e').find('e')
# print(charhidden)
# print(temp)
# print(hiddenrandom)
with open(file, 'r') as f:
line = f.readline()
for keys in randomhidden:
for key, value in randomhidden.items():
if key == keys:
temp = keys
print(f'SET "{temp}={randomhidden.get(keys)}"')
while line:
for i in range(len(line)):
if(line[i].isspace()):
print(end = " ")
elif(line[i]=='"'):
print('"',end="")
# elif(line[i]=="="):
# print("=",end="")
# elif(line[i]=="=="):
# print("==",end="")
elif(line[i]=="("):
print("(",end="")
elif(line[i]==")"):
print(")",end="")
# elif(line[i]==":"):
# print(":",end="")
elif(line[i]=="@"):
print("cls")
print("@", end="")
elif(line[i] == "%"):
print("%", end="")
elif(line[i] == ":"):
print(":", end="")
elif(line[i] == "&"):
print("&", end="")
else:
print(f"%{hiddenrandom.get(line[i])}:~{charhidden.get(line[i]).find(line[i])},1%", end = "")
print("")
line = f.readline()