Using Paramiko for server - python

I was wondering, I want to create a SSH server and a client with custom commands.
I thought of using Twisted for it, but I did not go well with the docs.
I decided to use Paramiko, but I wonder, is there any way to create a Paramiko server? Or only client?
Another question, let's say you can only create a client, can I create the client in Paramiko and the server using the socket module and connect to it? Is this possible?
If so, any advice?
Thanks in advance

Yes, Paramiko can be used both as an SSH client and server; see paramiko.Transport.start_server to get started.
If you go back and revisit Twisted, twisted.conch also implements SSH.

Related

How to route all traffic to local socks5 server?

I've implemented SOCKS5 server (which forwards connections over SSH to remote), it runs on 127.0.0.1:7070.
Now I'm trying to route all traffic through it.
I thought it's impossible, but apps like proxifier can do it... but how?
I'm looking for the Python solution on Windows. Any ideas?
Or at least make Chrome/IE to work this way...

Writing a proxyfier application with python

I'm new to coding in Python and what motivates me to start coding is the idea of writing a piece of software that will connect to a proxy server via SSH and then once connected will route all network traffic of the system trough it, seamlessly to the user.
I am actually using the paramiko module to connect to the server and it works fine, but now I would like to know if there is some way to make the system change its socks proxy configuration so I can route the traffic to the proxy, on a way the user doesn't need to do anything. Is there any existing module that will help on this task ?
Thank you.
You can see the existing project sshuttle, it transfers all traffic over ssh.

Python Proxy Through SSH

I'm being trying to
Log into a server using SHH (with Paramiko)
Use that connection like a proxy and route network traffic through it and out to the internet. So say I could set it as my proxy in Urllib2, Mechanize, Firefox, etc.).
Is the second part possible or will I have to have some sort of proxy server running on the server to get this to work?
You could implement a SOCKS proxy in the paramiko client that routes connections across the SSH tunnel via paramiko's open_channel method. Unfortunately, I don't know of any out-of-the-box solution that does this, so you'd have to roll your own. Alternatively, run a SOCKS server on the server, and just forward that single port via paramiko.

Emulating SSH's SOCKS Proxy Tunnel in Python

I used to create a SOCKS connection between a windows client and linux server using SSH server and putty. However, the firewall between the client and server is now able to identify SSH packets and drop them.
I was wondering if I can emulate such behavior of SSH tunnels using python? Any recommendations on libraries or readings?
Thanks in advance.
Yes, yes you can. Pick your poison.
http://socksipy.sourceforge.net/
http://sourceforge.net/projects/pysocks/
http://code.google.com/p/socksipy-branch/
How can I use a SOCKS 4/5 proxy with urllib2?
http://google-api-python-client.googlecode.com/hg/docs/httplib2.socks.html
You can consider using paramiko for your SSH. Here is a nice link ssh-programming-with-paramiko
You can also try this ssh module which uses paramiko.

Determine user connecting a local socket with Python

If Python, if you are developing a system service that communicates with user applications through sockets, and you want to treat sockets connected by different users differently, how would you go about that?
If I know that all connecting sockets will be from localhost, is there a way to lookup through the OS (either on windows or linux) which user is making the connection request?
On Linux and other unixy system, you can use the ident service.
I'm not sure if Windows offers something similar.
Unfortunately, at this point in time the python libraries don't support the usual SCM_CREDENTIALS method of passing credentials along a Unix socket.
You'll need to use an "ugly" method as described in another answer to find it.
On Linux you can get the source (i.e. client-side) port of the socket and parse the output of the lsof(8) utility searching for who is using that port.
Here's the manual page.

Categories

Resources