Friday, November 24, 2006
The Socket Server
One of the elements that makes it possible for SKAPPS to be based on an Apache-PHP based system. Is the submitserver.py script. When this script is executed it opens a Socket on port 8081, typically on a user workstation at login. It directs any input on this port directly to a system command. A major security hole, yes i know, but who cares we are in an closed environment.
submitserver.py
----------------------------------------------------------------------------------
#!/usr/bin/env python
import socket
import os
print "-------------------------------------"
print " KMA Submitserver"
print " (Do not close this window!!!!)"
print "-------------------------------------"
port = 8081
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Accept UDP datagrams, on the given port, from any sender
s.bind(("", port))
print "waiting on port:", port
while 1:
# Receive up to 1,024 bytes in a datagram
data, addr = s.recvfrom(1024)
print "Received:", data, "from", addr
os.system(data + " &")
----------------------------------------------------------------------------------
So by creating a php socket client. We can now send system commands to the users workstation executede by this user.
----------------------------------------------------------------------------------
function shellSocketCmd($address,$command){
$service_port = 8081;
//create cocket connection
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$result = socket_connect($socket, $address, $service_port);
//write command to socket
socket_write($socket, $command, strlen($command));
//close socket
socket_close($socket);
}
----------------------------------------------------------------------------------
You can get the client ip by using the $REMOTE_ADDR variable.
This trick also works with the maya command port. Allowing you to send mel commands directly to maya from you php functions.
----------------------------------------------------------------------------------
function mayaSocketCmd($address,$command){
$service_port = 8086;
//create cocket connection
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, $address, $service_port);
//write command to socket
socket_write($socket, $command, strlen($command));
//close socket
socket_close($socket);
}
----------------------------------------------------------------------------------
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment