- install rdesktop
For OpenSuse:
- Connection:
public List <String> packagesToScan() { return scanPackages.stream() .map(ScanPersistencePackage::asStrings) .flatMap(Collection::stream) .collect(Collectors.toList()); }And concrete persistence configuration for our module:
adduser bastion passwd bastion
vim /etc/ssh/sshd_config
systemctl restart ssh systemctl status sshd
[vq@localhost~]# systemctl status sshd ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2018-07-04 10:02:06 UTC; 32s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 11595 (sshd) CGroup: /system.slice/sshd.service └─11595 /usr/sbin/sshd -D Jul 04 10:02:06 systemd[1]:Starting OpenSSH server daemon... Jul 04 10:02:06 sshd[11595]: Server listening on 0.0.0.0 port 22 Jul 04 10:02:06 sshd[11595]: Server listening on :: port 22 Jul 04 10:02:06 *** systemd[1]: Started OpenSSH server daemon.Now you can't log in via the root user. You can see if this configuration checks out.
vq@localhost:~> ssh root@X.X.X.X root@X.X.X.X's password: Permission denied, please try again.
sudo yum install epel-release sudo yum install fail2ban
cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local vim jail.local
[DEFAULT] backend = systemd
[sshd] enabled = true
bantime = 1000 findtime = 1000 maxretry = 3
sudo systemctl enable fail2ban sudo systemctl start fail2ban
adduser usr passwd usr
ssh-keygen
ssh-copy-id -i ~/.ssh/name.pub usr@IP
ssh -i name usr@IP
vim /etc/ssh/sshd_config PasswordAuthentication no PermitRootLogin no
yum -y install policycoreutils-python semanage port -a -t ssh_port_t -p tcp 2597
vim /etc/ssh/sshd_configCheck configuration file
sshd -t
sudo systemctl restart sshd
sudo netstat -lntp | grep ssh
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="BASTION_IP/32" port protocol="tcp" port="2597" accept'
firewall-cmd --get-default-zone
firewall-cmd --list-all
iptables -I INPUT -p tcp -s BASTION_IP --dport 2597 -j ACCEPT iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 2597 -j DROP
iptables -L --line-numbers sudo iptables -D INPUT {line}
Host bast Hostname BASTION_IP ForwardAgent yes User bastion
ssh-add ~/.ssh/name_rsa
ssh bast
ssh app@IP -p PORT
scp -P PORT app@IP:/src_path /dest_path
scp -P PORT bastion@ip:/src_path /dest_pathor
scp -P PORT bast:/src_path /dest_path
scp /src_path bastion:/dest_path
[root@localhost tmp]# ll total 12 drwx------ 2 bastion bastion 4096 Sep 7 17:35 ssh-mKX88v0Vlolet's open the temporary file
[root@localhost tmp]# cd ssh-mKX88v0Vlo/ [root@localhost ssh-mKX88v0Vlo]# ll total 0 srwxr-xr-x 1 bastion bastion 0 Sep 7 17:35 agent.10507Let's see connections to this process id.
netstat -nxp | grep 10507result:
unix [ ] STREAM CONNECTED 501384 10507/sshd: bastionand who is connected?
lsof -i -a -p 10507result:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 10507 bastion 3u IPv4 501301 0t0 TCP *IP*:ssh->*IP*:8279 (ESTABLISHED)We can also see socket files:
cd /proc/10507/fd/ lsresult:
lrwx------ 1 root root 64 Sep 7 17:46 0 -> /dev/null lrwx------ 1 root root 64 Sep 7 17:46 1 -> /dev/null lrwx------ 1 root root 64 Sep 7 17:46 10 -> /dev/ptmx lrwx------ 1 root root 64 Sep 7 17:46 14 -> /dev/ptmx lrwx------ 1 root root 64 Sep 7 17:46 15 -> /dev/ptmx lrwx------ 1 root root 64 Sep 7 17:46 2 -> /dev/null lrwx------ 1 root root 64 Sep 7 17:46 3 -> socket:[501994] lrwx------ 1 root root 64 Sep 7 17:46 4 -> socket:[502069] lrwx------ 1 root root 64 Sep 7 17:46 5 -> socket:[502072] l-wx------ 1 root root 64 Sep 7 17:46 6 -> /run/systemd/sessions/1836.ref lr-x------ 1 root root 64 Sep 7 17:46 7 -> pipe:[502079] l-wx------ 1 root root 64 Sep 7 17:46 8 -> pipe:[502079] lrwx------ 1 root root 64 Sep 7 17:46 9 -> socket:[502080]And what happens when client will be connected to remote server? let's see:
lrwx------ 1 root root 64 Sep 7 17:46 0 -> /dev/null lrwx------ 1 root root 64 Sep 7 17:46 1 -> /dev/null lrwx------ 1 root root 64 Sep 7 17:46 10 -> /dev/ptmx lrwx------ 1 root root 64 Sep 7 17:48 11 -> socket:[502267] lrwx------ 1 root root 64 Sep 7 17:46 14 -> /dev/ptmx lrwx------ 1 root root 64 Sep 7 17:46 15 -> /dev/ptmx lrwx------ 1 root root 64 Sep 7 17:46 2 -> /dev/null lrwx------ 1 root root 64 Sep 7 17:46 3 -> socket:[501994] lrwx------ 1 root root 64 Sep 7 17:46 4 -> socket:[502069] lrwx------ 1 root root 64 Sep 7 17:46 5 -> socket:[502072] l-wx------ 1 root root 64 Sep 7 17:46 6 -> /run/systemd/sessions/1836.ref lr-x------ 1 root root 64 Sep 7 17:46 7 -> pipe:[502079] l-wx------ 1 root root 64 Sep 7 17:46 8 -> pipe:[502079] lrwx------ 1 root root 64 Sep 7 17:46 9 -> socket:[502080]We can even see if socket file is used using netstat:
unix 3 [ ] STREAM CONNECTED 502267 10561/sshd: bastion /tmp/ssh-oVoMXC6vb8/agent.10561 unix 3 [ ] STREAM CONNECTED 502072 10561/sshd: bastionbut wait we need to steal the socket information while the session of bastion host is open. Oh, we also need destination server IP, so just use netstat It's funny but you might find something like that on the internet.:
netstat -tn 2>/dev/null grep :22 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | headSometimes people try to demonstrate their knowledge but just make everything simple.
netstat -tnThe final step to use the forwarded socket file
eval "$(ssh-agent -s)" SSH_AUTH_SOCK=/tmp/ssh-EAKxOdL4fl/agent.10507Check if the key is loaded.
ssh-add -lresult should be something like that:
2048 SHA256:2Psdl..B5KQ /home/usr/.ssh/name_rsa (RSA)Ok. We have seen that Agent Forwarding is a problem. But where is the solution? Fortunately, we can just use a proxy command. So let's rewrite our configuration:
Host app Hostname *.*.*.* IdentityFile ~/.ssh/your_rsa User ******* Port **** ProxyCommand ssh -W %h:%p bast Host bast Hostname *.*.*.* ForwardAgent no User ******Now it's very simple to connect your server
ssh appDo you want to download something from bastion?
scp bast:/home/bastion/sh ~/Maybe you want to download something from the remote server via the bastion tunnel:
scp -P **** app:/src_path /dest_pathMaybe you want to ypload something to remote server via the bastion tunel:
scp -P **** app:/src_path /dest_path
touch /usr/local/sbin/{launcher_name}.sh
#!/bin/bash java -jar /root/{name}.jar
chmod +x {launcher_name}.sh
touch /etc/systemd/system/{service_name}.service
[Unit] Description=Application launcher service [Service] Type=simple ExecStart=/usr/local/sbin/{launcher_name}.sh TimeoutStartSec=0 [Install] WantedBy=default.target
chmod 664 {service_name}.service
systemctl daemon-reload
systemctl enable {service_name} systemctl start {service_name}
#! /bin/sh # /etc/init.d/{service_name} ### BEGIN INIT INFO # Provides: {service_name} # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Example of init service. ### END INIT INFO # Actions provided to make it LSB-compliant case "$1" in start) export DISPLAY=:0 sh {launcher_name}.sh ;; stop) echo "Stopping" ... ;; restart) echo "Restarting" ;; force-reload) echo "Reloading" ... ;; status) echo "Status" ... ;; *) echo "Usage: /etc/init.d/{service_name} {start|stop|restart|force-reload|status}" exit 1 ;; esac exit 0
apt-get install sudo -y
usermod -a -G sudo vq
update-alternatives --config editor
vq ALL=NOPASSWD:/sbin/reboot
sudo reboot
cd /etc/sudoers.d touch vq vim vq
%vq ALL= NOPASSWD: /bin/systemctl start firewalld %vq ALL= NOPASSWD: /bin/systemctl stop firewalld %vq ALL= NOPASSWD: /bin/systemctl status firewalld
sudo systemctl start firewalld sudo systemctl stop firewalld sudo systemctl status firewalld
There are another implementations too but know let's talk for about ntpd and timedatectl.yum install ntpd systemctl enable ntpd firewall-cmd --add-service=ntp --permanent
apt-get install ntpd apt-get install ntpdate
server 0.[YOUR_POOLl] server 1.[YOUR_POOLl]
server 127.127.1.0 fudge 127.127.1.0 stratum 10
server X.X.X.X
ntpdate -u X.X.X.X
systemctl start ntpd
service ntp start or systemctl start ntp
[vq@centos etc]# ntpq -p remote refid st t when poll reach delay offset jitter =========================================================== *LOCAL(0) .LOCL. 10 l 40 64 17 0.000 0.000 0.000
vq@debian:/var/log# systemctl status
systemd-timesyncd.service ● systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/systemd-timesyncd.service.d └─disable-with-time-daemon.conf Active: inactive (dead) Condition: start condition failed at Fri 2018-07-27 13:31:23 +04; 35s ago └─ ConditionFileIsExecutable= !/usr/sbin/ntpd was not met Docs: man:systemd-timesyncd.service(8)
/etc/systemd/timesyncd.conf
[Time] NTP= ${URLS} FallbackNTP=${URLS} #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048
vq@debian:/etc# timedatectl Local time: Fri 2018-07-27 13:27:36 +04 Universal time: Fri 2018-07-27 09:27:36 UTC RTC time: Fri 2018-07-27 09:46:02 Time zone: Asia/Tbilisi (+04, +0400) Network time on: YES NTP synchronized: YES RTC in local TZ: YES