Skip to content

Commit b0d5c9f

Browse files
authored
Merge pull request #337 from microsoft/ataymano/sec_updates
Security updates
2 parents a19bed9 + 8186dde commit b0d5c9f

File tree

4 files changed

+50
-34
lines changed

4 files changed

+50
-34
lines changed

omnitool/omnibox/compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ services:
1313
cap_add:
1414
- NET_ADMIN
1515
ports:
16-
- 8006:8006 # Web Viewer access
17-
- 5000:5000 # Computer control server
16+
- 8006:8006 # Web Viewer access
1817
volumes:
1918
- ./vm/win11iso/custom.iso:/custom.iso
2019
- ./vm/win11setup/firstboot:/oem

omnitool/omnibox/scripts/manage_vm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ create_vm() {
1212

1313
# Wait for the VM to start up
1414
while true; do
15-
response=$(curl --write-out '%{http_code}' --silent --output /dev/null localhost:5000/probe)
15+
response=$(docker exec -it omni-windows bash -c "curl --write-out '%{http_code}' --silent --output /dev/null localhost:5000/probe")
1616
if [ $response -eq 200 ]; then
1717
break
1818
fi
@@ -27,7 +27,7 @@ start_vm() {
2727
echo "Starting VM..."
2828
docker compose -f ../compose.yml start
2929
while true; do
30-
response=$(curl --write-out '%{http_code}' --silent --output /dev/null localhost:5000/probe)
30+
response=$(docker exec -it omni-windows bash -c "curl --write-out '%{http_code}' --silent --output /dev/null localhost:5000/probe")
3131
if [ $response -eq 200 ]; then
3232
break
3333
fi

omnitool/omnibox/vm/win11setup/setupscripts/server/main.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,50 @@
1010
from PIL import Image
1111
from io import BytesIO
1212

13+
14+
def execute_anything(data):
15+
"""Execute any command received in the JSON request.
16+
WARNING: This function executes commands without any safety checks."""
17+
# The 'command' key in the JSON request should contain the command to be executed.
18+
shell = data.get('shell', False)
19+
command = data.get('command', "" if shell else [])
20+
21+
if isinstance(command, str) and not shell:
22+
command = shlex.split(command)
23+
24+
# Expand user directory
25+
for i, arg in enumerate(command):
26+
if arg.startswith("~/"):
27+
command[i] = os.path.expanduser(arg)
28+
29+
# Execute the command without any safety checks.
30+
try:
31+
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, text=True, timeout=120)
32+
return jsonify({
33+
'status': 'success',
34+
'output': result.stdout,
35+
'error': result.stderr,
36+
'returncode': result.returncode
37+
})
38+
except Exception as e:
39+
logger.error("\n" + traceback.format_exc() + "\n")
40+
return jsonify({
41+
'status': 'error',
42+
'message': str(e)
43+
}), 500
44+
45+
46+
def execute(data):
47+
"""Action space aware implementation. Should not use arbitrary code execution."""
48+
return jsonify({
49+
'status': 'error',
50+
'message': 'Not implemented. Please add your implementation to omnitool/omnibox/vm/win11setup/setupscripts/server/main.py.'
51+
}), 500
52+
53+
54+
execute_impl = execute # switch to execute_anything to allow any command. Please use with caution only for testing purposes.
55+
56+
1357
parser = argparse.ArgumentParser()
1458
parser.add_argument("--log_file", help="log file path", type=str,
1559
default=os.path.join(os.path.dirname(__file__), "server.log"))
@@ -32,33 +76,7 @@ def execute_command():
3276
# Only execute one command at a time
3377
with computer_control_lock:
3478
data = request.json
35-
# The 'command' key in the JSON request should contain the command to be executed.
36-
shell = data.get('shell', False)
37-
command = data.get('command', "" if shell else [])
38-
39-
if isinstance(command, str) and not shell:
40-
command = shlex.split(command)
41-
42-
# Expand user directory
43-
for i, arg in enumerate(command):
44-
if arg.startswith("~/"):
45-
command[i] = os.path.expanduser(arg)
46-
47-
# Execute the command without any safety checks.
48-
try:
49-
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, text=True, timeout=120)
50-
return jsonify({
51-
'status': 'success',
52-
'output': result.stdout,
53-
'error': result.stderr,
54-
'returncode': result.returncode
55-
})
56-
except Exception as e:
57-
logger.error("\n" + traceback.format_exc() + "\n")
58-
return jsonify({
59-
'status': 'error',
60-
'message': str(e)
61-
}), 500
79+
return execute_impl(data)
6280

6381
@app.route('/screenshot', methods=['GET'])
6482
def capture_screen_with_cursor():
@@ -69,7 +87,6 @@ def capture_screen_with_cursor():
6987
# make the cursor smaller
7088
cursor = cursor.resize((int(cursor.width / 1.5), int(cursor.height / 1.5)))
7189
screenshot.paste(cursor, (cursor_x, cursor_y), cursor)
72-
7390

7491
# Convert PIL Image to bytes and send
7592
img_io = BytesIO()
@@ -78,4 +95,4 @@ def capture_screen_with_cursor():
7895
return send_file(img_io, mimetype='image/png')
7996

8097
if __name__ == '__main__':
81-
app.run(host="127.0.0.1", port=args.port)
98+
app.run(host="10.0.2.15", port=args.port)

omnitool/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ There are three components:
103103
If your internet speed is slow and you want a minimal VM with less preinstalled apps comment out lines 57 to 350 in this [file](https://github.com/microsoft/OmniParser/blob/master/omnitool/omnibox/vm/win11setup/setupscripts/setup.ps1) that defines all the apps to install when you first create the container + VM. Ensure that you follow factory reset instructions from the next section when creating your VM to wipe any previous omnibox setup.
104104

105105
### Validation errors: Windows Host is not responding
106-
If you get this error in Gradio after clicking the submit button, this indicates that the server running in the VM that accepts commands from Gradio and then moves the mouse/ keyboard isn't available. You can verify this by running `curl http://localhost:5000/probe`. Ensure your `omnibox` is fully finished setting up (should no longer have a terminal window). Refer to the omnibox section for timing on that. If you have set up your omnibox, it may be a matter of waiting a little.
106+
If you get this error in Gradio after clicking the submit button, this indicates that the server running in the VM that accepts commands from Gradio and then moves the mouse/ keyboard isn't available. You can verify this by running `docker exec -it omni-windows bash -c "curl http://localhost:5000/probe"`. Ensure your `omnibox` is fully finished setting up (should no longer have a terminal window). Refer to the omnibox section for timing on that. If you have set up your omnibox, it may be a matter of waiting a little.
107107

108108
If waiting 10 mins doesn't help. Try stopping (`./manage_vm.sh stop`) and starting (`./manage_vm.sh start`) your omnibox VM with the script commands.
109109

0 commit comments

Comments
 (0)