Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ncouture/MockSSH
Mock an SSH server and define all commands it supports (Python, Twisted)
https://github.com/ncouture/MockSSH
dsl emulator hylang mock python shell ssh ssh-server twisted
Last synced: 3 months ago
JSON representation
Mock an SSH server and define all commands it supports (Python, Twisted)
- Host: GitHub
- URL: https://github.com/ncouture/MockSSH
- Owner: ncouture
- License: other
- Created: 2013-01-05T23:51:38.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-12-19T20:45:05.000Z (11 months ago)
- Last Synced: 2024-08-03T23:05:49.115Z (3 months ago)
- Topics: dsl, emulator, hylang, mock, python, shell, ssh, ssh-server, twisted
- Language: Python
- Size: 80.1 KB
- Stars: 123
- Watchers: 6
- Forks: 23
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
MockSSH
=======Mock an SSH server and all commands it supports.
Purpose
-------
This project was developed to emulate operating systems
behind SSH servers in order to test task automation without
having access to the real servers.There has been user interest in using MockSSH to perform
end-to-end unit tests against SSH servers and as such a
threaded version of MockSSH server is available as of
version 1.4 (thanks to Claudio Mignanti).Installation
------------
MockSSH depends on libraries that do not support Python 3k.
```shell
mkvirtualenv -p `which python2` mocksshenv
pip install mockssh
```MockSSH in Python
-----------------
MockSSH aims to be as easy to use as possible.Refer to the mock_cisco.py and mock_F5.py in the examples/
directory for an overview on how to use it.MockSSH in LISP
---------------
Efforts were invested in simplifying the use of MockSSH
with [HyLang](http://hylang.org/).As a result a DSL is released with this project and
resides in the *mocksshy/* directory.Using the DSL will allow you to use MockSSH by writing
something that is closer to a configuration file than
a program.For comparison, here are two MockSSH servers
implementations providing the same functionality:*Python*
```python
import MockSSHdef passwd_change_protocol_prompt(instance):
instance.protocol.prompt = "hostname #"
instance.protocol.password_input = Falsedef passwd_write_password_to_transport(instance):
instance.writeln("MockSSH: password is %s" % instance.valid_password)command_passwd = MockSSH.PromptingCommand(
name='passwd',
password='1234',
prompt="Password: ",
success_callbacks=[passwd_change_protocol_prompt],
failure_callbacks=[passwd_write_password_to_transport])users = {'admin': '1234'}
commands = [command_passwd]
MockSSH.runServer(commands,
prompt="hostname>",
interface='127.0.0.1',
port=2222,
**users)
```*HyLang*
```clojure
(import MockSSH)
(require mocksshy.language)(mock-ssh :users {"testuser" "1234"}
:host "127.0.0.1"
:port 2222
:prompt "hostname>"
:commands [
(command :name "passwd"
:type "prompt"
:output "Password: "
:required-input "1234"
:on-success ["prompt" "hostname#"]
:on-failure ["write" "Pass is 1234..."]))
```Unit Testing with MockSSH
-------------------------
As shown from the unit tests in the tests/ directory, it is possible to use
a threaded MockSSH server to perform end-to-end unit tests against mocked
SSH services.Note that this may not be the right approach depending on your use case as only
one Twisted reactor can run at the same time and reactors cannot be restarted.Credits
-------
MockSSH is derived from [kippo](https://github.com/desaster/kippo/), an SSH honeypot.