Tuesday, October 20, 2020

SSH_ASKPASS


$ man ssh
...
SSH_ASKPASS

If ssh needs a passphrase, it will read the
passphrase from the current terminal if it was run
from a terminal. If ssh does not have a terminal
associated with it but DISPLAY and SSH_ASKPASS are
set, it will execute the program specified by
SSH_ASKPASS and open an X11 window to read the
passphrase. This is particularly useful when call‐
ing ssh from a .xsession or related script. (Note
that on some machines it may be necessary to redi‐
rect the input from /dev/null to make this work.)
...

Keep in mind that ssh stands for secure shell, and if you store your user, host and password in plain text files you are misleading the tool an creating a possible security gap

$ cat ~/echo_pass
echo toor
$

$ cat ssh_session
export SSH_ASKPASS='~/echo_pass'
setsid ssh root@127.0.0.1

$ chmod u+x echo_pass
$ chmod u+x ssh_session

 ./ssh_session

$ ./ssh_session
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-121-generic x86_64)

operator@server:~$

https://stackoverflow.com/questions/1340366/how-to-make-ssh-receive-the-password-from-stdin

Monday, October 19, 2020

SSH_ASKPASS

 

#!/bin/bash

hostname="127.0.0.1"
username="u"
password="p"

command='ls -l'

ask="/tmp/ask"

echo "echo $password" > $ask
chmod +x $ask

SSH_OPTIONS='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'

SSH_ASKPASS=$ask
DISPLAY=localhost:0.0

export DISPLAY
export SSH_ASKPASS

setsid ssh $SSH_OPTIONS $username@$hostname $command && echo '\n SSH OK\n' || echo '\nSSH PROBLEM\n'

Thursday, October 15, 2020

Python SSHClient invoke interactive shell

...

import threading, paramiko

class ssh:
shell = None
client = None
transport = None

def __init__(self, address, username, password):
print("Connecting to server on ip", str(address) + ".")
self.client = paramiko.client.SSHClient()
self.client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
self.client.connect(address, username=username, password=password, look_for_keys=False)
self.transport = paramiko.Transport((address, 22))
self.transport.connect(username=username, password=password)

thread = threading.Thread(target=self.process)
thread.daemon = True
thread.start()

def closeConnection(self):
if(self.client != None):
self.client.close()
self.transport.close()

def openShell(self):
self.shell = self.client.invoke_shell()

def sendShell(self, command):
if(self.shell):
self.shell.send(command + "\n")
else:
print("Shell not opened.")

def process(self):
global connection
while True:
# Print data when available
if self.shell != None and self.shell.recv_ready():
alldata = self.shell.recv(1024)
while self.shell.recv_ready():
alldata += self.shell.recv(1024)
strdata = str(alldata, "utf8")
strdata.replace('\r', '')
print(strdata, end = "")
if(strdata.endswith("$ ")):
print("\n$ ", end = "")


sshUsername = ''
sshPassword = ''
sshServer = ''


connection = ssh(sshServer, sshUsername, sshPassword)
connection.openShell()
while True:
connection.sendShell('./script.sh')
command = input('$ ')
if command.startswith(" "):
command = command[1:]
connection.sendShell(command)

https://daanlenaerts.com/blog/2016/07/01/python-and-ssh-paramiko-shell/

Tuesday, October 13, 2020

Python, paramiko, SSHClient, invoke_shell() in bytes

from paramiko import SSHClient, AutoAddPolicy

hostname = '127.0.0.1'
username = 'admin'
password = 'password'

client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())

client.connect(hostname, port = 22,
username = username,
password = password,
look_for_keys = False,
allow_agent = False)

device_access = client.invoke_shell()
device_access.send(b'ls -lh\n')
output = device_access.recv(65000)
print(output.decode('ascii'))

client.close

Wednesday, October 7, 2020

Alpine Linux

1. Download

https://alpinelinux.org/downloads/


2. Login with root


3. Change the password

passwd


4. Set temporary IP (static or dhcp)

ifconfig eth0 10.1.1.1

or

udhcpc -i eth0


5. Install the openssh package

apk add openssh


5. View/change SSH config

/etc/ssh/sshd_config


6. Start SSH service

/etc/init.d/sshd start

Monday, June 17, 2019

Linux show hidden files only

There are a few ways can be used to accomplish this task. The first 2 commands produce almost similar output
echo .*
ls -d .*
If you prefer it in long listing format, use `-l`
ls -dl .*
 or
echo .* | tr ' ' '\n'

Examples:
c-kurity@Linux:~$ echo .* . .. .bash_aliases .bash_history .bash_logout .bashrc .cache .config c-kurity@Linux:~$
c-kurity@Linux:~$ ls -d .* . .bash_logout .. .bashrc .bash_aliases .cache .bash_history .config c-kurity@Linux:~$

Wednesday, March 16, 2011

How to find listening / open ports on a computer?

So how do I tell if a TCP or UDP network port is open or not?

Microsoft Windows
1. To find open ports on a computer, you can use netstat command line.

Netstat (network statistics) is a command-line tool that displays network connections (both incoming and outgoing), routing tables, and a number of network interface statistics. It is available on Unix, Unix-like, and Windows NT-based operating systems.
It is used for finding problems in the network and to determine the amount of traffic on the network as a performance measurement.

a. To display all open ports, open DOS command, type netstat and press Enter.
b. To list all listening ports, use netstat -an | find /i "listening" command.
c. To see what ports your computer actually communicates with, use netstat -an | find /i "established"
d. To find specified open port, use find switch. For example, to find if the port 3389 is open or not, do netstat -an | find /i "3389".

Example: Port 3389 is closed / not listening
1. netstat -an | find "3389" command shows nothing

2.1. You can also test by telneting to localhost or 127.0.0.1 at specific port you want to check.
telnet localhost 3389  or   telnet 127.0.0.1 3389

The following error message will popup if the port is closed / not listening.
"Connecting To 3389...Could not open connection to the host, on port 23: Connect failed"


Example: Port is open / listening
1. netstat -an | find "3389" command shows "LISTENING" message

2.1. You can also test by telneting to localhost or 127.0.0.1 at specific port you want to check.
telnet localhost 135 or telnet 127.0.0.1 135

2.2. Once you press enter, a blank screen as image below shows that the port is listening.

e. You can use PULIST from the Windows Resource Kit to find which process is using a specified port. For example, pulist | find /i "4125" may display

Process PID User
mad.exe 4125 Chicagotech/blin

Or you can use tasklist to find PID.

Reference:
http://en.wikipedia.org/wiki/Netstat
http://nixcraft.com/getting-started-tutorials/622-windows-how-do-i-tell-if-tcp-network-port-open-not.html
http://www.speedguide.net/faq_in_q.php?qid=115
http://www.howtonetworking.com/command/openport1.htm
http://www.techrepublic.com/blog/security/list-open-ports-and-listening-services/443

Related post:

Related Posts with Thumbnails