Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
ab18fe46
Commit
ab18fe46
authored
Sep 24, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stash
parent
de0f8c24
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
13 deletions
+52
-13
hands.py
apps/terminal/hands.py
+5
-0
README.md
apps/terminal/keys/README.md
+0
-0
server.py
apps/terminal/server.py
+47
-13
No files found.
apps/terminal/hands.py
0 → 100644
View file @
ab18fe46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from
users.utils
import
ssh_key_gen
apps/terminal/keys/README.md
0 → 100644
View file @
ab18fe46
server.py
→
apps/terminal/
server.py
View file @
ab18fe46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import
sys
import
os
import
django
BASE_DIR
=
os
.
path
.
dirname
(
__file__
)
APP_DIR
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
BASE_DIR
))
sys
.
path
.
append
(
APP_DIR
)
os
.
environ
[
'DJANGO_SETTINGS_MODULE'
]
=
'jumpserver.settings'
try
:
django
.
setup
()
except
IndexError
:
pass
import
base64
from
binascii
import
hexlify
import
os
import
sys
import
threading
import
traceback
import
tty
import
termios
import
struct
,
fcntl
,
signal
,
socket
,
select
import
struct
import
fcntl
import
signal
import
socket
import
select
import
errno
import
paramiko
from
paramiko.py3compat
import
b
,
u
,
decodebytes
from
.hands
import
ssh_key_gen
paramiko
.
util
.
log_to_file
(
'demo_server.log'
)
...
...
@@ -24,24 +41,42 @@ host_key = paramiko.RSAKey(filename='test_rsa.key')
class
SSHService
(
paramiko
.
ServerInterface
):
# 'data' is the output of base64.encodestring(str(key))
# (using the "user_rsa_key" files)
data
=
(
b
'AAAAB3NzaC1yc2EAAAABIwAAAIEAyO4it3fHlmGZWJaGrfeHOVY7RWO3P9M7hp'
b
'fAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMC'
b
'KDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iT'
b
'UWT10hcuO4Ks8='
)
good_pub_key
=
paramiko
.
RSAKey
(
data
=
decodebytes
(
data
))
# data = (b'AAAAB3NzaC1yc2EAAAABIwAAAIEAyO4it3fHlmGZWJaGrfeHOVY7RWO3P9M7hp'
# b'fAu7jJ2d7eothvfeuoRFtJwhUmZDluRdFyhFY/hFAh76PJKGAusIqIQKlkJxMC'
# b'KDqIexkgHAfID/6mqvmnSJf0b5W8v5h2pI/stOSwTQ+pxVhwJ9ctYDhRSlF0iT'
# b'UWT10hcuO4Ks8=')
# good_pub_key = paramiko.RSAKey(data=decodebytes(data))
ssh_key_path
=
os
.
path
.
join
(
BASE_DIR
,
'keys'
,
'ssh_host_key'
)
ssh_pub_key_path
=
ssh_key_path
+
'.pub'
def
__init__
(
self
):
self
.
event
=
threading
.
Event
()
@classmethod
def
get_host_key
(
cls
):
if
os
.
path
.
isfile
(
cls
.
ssh_pub_key_path
):
with
open
(
cls
.
ssh_pub_key_path
)
as
f
:
ssh_pub_key
=
f
.
read
()
else
:
ssh_key
,
ssh_pub_key
=
cls
.
host_key_gen
()
return
ssh_pub_key
@classmethod
def
host_key_gen
(
cls
):
ssh_key
,
ssh_pub_key
=
ssh_key_gen
()
with
open
(
cls
.
ssh_key_path
,
'w'
)
as
f
:
with
open
(
cls
.
ssh_pub_key_path
,
'w'
)
as
f2
:
f
.
write
(
ssh_key
)
f2
.
write
(
ssh_pub_key
)
return
ssh_key
,
ssh_pub_key
def
check_channel_request
(
self
,
kind
,
chanid
):
if
kind
==
'session'
:
return
paramiko
.
OPEN_SUCCEEDED
return
paramiko
.
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
def
check_auth_password
(
self
,
username
,
password
):
print
(
username
,
password
)
if
(
username
==
'robey'
)
and
(
password
==
'foo'
):
return
paramiko
.
AUTH_SUCCESSFUL
return
paramiko
.
AUTH_FAILED
...
...
@@ -151,7 +186,6 @@ class SSHServer:
pass
print
(
server_data
)
except
Exception
as
e
:
print
(
'*** Caught exception: '
+
str
(
e
.
__class__
)
+
': '
+
str
(
e
))
traceback
.
print_exc
()
...
...
@@ -167,7 +201,7 @@ class SSHServer:
try
:
client
,
addr
=
self
.
sock
.
accept
()
print
(
'Listening for connection ...'
)
threading
.
Thread
(
target
=
self
.
handle_ssh_request
,
args
=
(
client
,
addr
))
.
start
()
threading
.
Thread
(
target
=
self
.
handle_ssh_request
,
args
=
(
client
,
addr
))
.
start
()
except
Exception
as
e
:
print
(
'*** Bind failed: '
+
str
(
e
))
traceback
.
print_exc
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment