美文网首页
[iOS逆向]17、SSH

[iOS逆向]17、SSH

作者: 史记_d5da | 来源:发表于2022-01-26 23:22 被阅读0次

1、SSH

1.1、概念

SSH 是一种网络协议,用于计算机之间的加密登录。
1995年,芬兰学者Tatu Ylonen设计了SSH协议,将登录信息全部加密,成为互联网安全的一个基本解决方案,迅速在全世界获得推广,目前已经成为Linux系统的标准配置。

1.2、SSH 的登录过程(免密公钥登录)
1.2.1、非对称加密

① 远程 Server 收到 Client 端用户的登录请求,Server 把自己的公钥发给用户。
Client 使用这个公钥,将密码进行加密。
Client 将加密的密码发送给 Server 端。
④ 远程Server 用自己的私钥,解密登录密码,然后验证其合法性。
⑤ 若验证结果,给 Client 相应的响应。

非对称登录
1.2.2、公钥认证流程(免密登录)

Client端用户将自己的公钥存放在Server上,追加在文件authorized_keys中。
Server收到登录请求后,随机生成一个字符串 str1,并发送给Client
Client用自己的私钥对字符串str1进行加密。
④ 将加密后字符串发送给 Server
Server 用之前存储的公钥进行解密,比较解密后的str2str1
⑥ 根据比较结果,返回客户端登陆结果。

公钥登录
1.2.3、模拟公钥登录

① 电脑本地生成公钥私钥
ssh-keygen && ~/.ssh ls -a

id_rsa (私钥)     id_rsa.pub (公钥)  known_hosts

② 拷贝id_rsa.pub 到手机
ssh-copy-id root@192.168.3.9ssh-copy-id -i id_rsa.pub root@192.168.3.9

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/shiji/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.3.9's password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'root@192.168.3.9'"
and check to make sure that only the key(s) you wanted were added.

③ 登录到ssh无须输入密码
ssh root@192.168.3.9
如果设置了 id_rsa.pub 密码,则在登录时需要输入 id_rsa.pub 密码

[shiji@shijideMacBook-Pro Theos-Script-master ]$ ssh root@192.168.3.9
Enter passphrase for key '/Users/shiji/.ssh/id_rsa': 

④ 公钥登录的pubkey 查看
cat ~/.ssh/authorized_keys
显示多条追加的 publickey

shijiteki-iPhone:~ root# cat ~/.ssh/authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDTUzUD55ljQwdqZBKHIhRQTqxd/wgGTl3k9iPjsE2z6K4AU3D4UzlUlW6gUGxE+yLH9h7PejyCA/z+RYPg/Q31+1t5cD2GdJibdgz9LM9kAnPbKWYPkiIWtMFYHsjUzikPuxE/ynYSfGzr33FOfI8g+MoFkIsn0tgA3dOULjO54hHYGws7bZ3zxkICKbJN4pqH8Xxn2VWf6Ztu9hvyGRmpDsmo24LWi06YDldCbO82B/F8cgzqD9PtL678yejNyYEJ3g8Yr3aYUpXtbgu4kEmR5+XhCI2G3bQ7hqzV9gKBjdZDf1QfObDf3MslMF04FiD89ItIXdPotPRwImMrNIH7NNmGYNdCCSOlPwqgd3BkQfZmxOi5UisNTOB18R8BMPSOut2OhcXSCg29BAfmt4hpGet1JyJzZBUFYvHsdGEs7mQYQAXDc21Q2z8KxINXQSiOM67nerbNwDP3yIIveMC/ENs6iQxHYXmlK/70dHFx4Z4LtehRg1gs7EXiQtBB/iU= shiji@shijideMacBook-Pro.local
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCg8DIeJJ2ly8M5yLoYezoELsQ5fXdF9bTT/wGv/ujmbZVCiPvBy/pk2+S3hnGHxuAEB/BC9hkoaAj+8H4W6M2Y7lK0/S9SUUTD9JaJovWmSY770VpCe7AAK8YdkLdlBFJr6bGpuhhecyGSLRpgfbLaOfECCKRRENa+Jy68Vktgfzf7QFI+JOpovIHmtq/QTtINW3w4mJz7q4zyS1fUJScjTG9bS8TAhYpkSLwS2u39JekDkDKngL1v9NQ7pKoyBMXywI0Ih+hWifxmF5bbJo3QDDX9iV2hbrbIcHcY/6OcaIOlw+rYxKMO3iZvlpmNlE83l7xDtj400kHAj5iNnvlVV9STPII0GVv3vNfT5M5+dEm50mk3736sGM3D39uLzmh/Psz10vcqxjTvUWXOaoc5di4hJeFi5Zo+vx/kLwWIFp19xr9bUnTXvpruYambFSF4+TFCkwbE+5QNmLScSZDClGR7Y7eTiNbNiXRKlHcyBg5pRmyMmMiDg2v4LgsXcUc= shiji@shijideMacBook-Pro.local
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDluhQS55+G7sKygUok3hAySy7nUKWxgszDFL1PmXd83/Ow7yWD3goJckGhTanCx7rWTigh4CpYlpHMHDDkz04WlngNEkRweJQvoETqmOmH2po+va4fmn/7GF6SPbYchcr7EKOzclUNS0xvI6ByOBdig5PxP4gwzUSLLM1Lh0r97M348TycGBvBBCVYzLjGfQLJVBKEWVjyB6LC/McDAaqGySasGfizdtsdSNnjNAHFMD7oV9JkENL3vmi+fU2F7oRUKz6jupPLvEkaGAGGlkyUxR+ggrRsHSJvGJfEv6xWibcKDF2Q0Ar3teLfn5dyDIRc9LlZMrAFhOalPkDrygnKRIOri/apkIChZftFUpVNDzgdQtpRQMvgpjIiFBsa9u0jImxa3ue7KtrEFR3PZJaQDszQL131FIHRt5dhN0tw5fs/UxXQU4BwZWvi9N7SPamjtJOFvw0UTMLWMh7rGfMZMniBHWQcxSJLrLPPk8oEpemQH4GTAe2rZA6Y22sks8E= shiji@shijideMacBook-Pro.local
1.2.4、SSH的其他操作

① 删掉保存的服务器地址的 key
ssh-keygen –R 服务器IP地址(当SSH登录手机,手机就是服务器)
know_hosts 文件:用于保存 SSH 登录服务器所接受的 key
在系统 ~/.ssh 目录中保存
ssh_host_rsa_key.pub 文件:作为 SSH 服务器发送给连接者的key
在系统 /etc/ssh 目录中保存
Config 文件
~/.ssh 目录下创建一个 config 文件。内部可以配置 ssh 登录的别名。

  • Host 别名
  • Hostname IP地址
  • User 用户名
  • Port 端口号

2、OpenSSH

OpenSSHSSHSecure SHell) 协议的免费开源实现。 SSH协议可以用来进行远程控制, 或在计算机之间传送文件。

2.1、OpenSSH的登录

iOS 下两个用户:Rootmobile

  • Root 用户:最高权限用户,可以访问任意文件
  • Mobile 用户:普通用户,只能访问改用户目录下文件 /var/Mobile
2.1.1、root 登录

在电脑终端输入 ssh 用户名@手机IP地址
$ssh root@192.168.31.231
SSH 如何对 Server 的公钥进行认证?在https中可以通过CA来进行公证,可是SSHpublish keyprivate key都是自己生成的,没法公证。只能通过Client端自己对公钥进行确认。通常在第一次登录的时候,系统首次会出现下面提示信息:

The authenticity of host 'ssh-server.example.com (192.168.3.9)' can't be established.
RSA key fingerprint is 98:2e:d7:e0:de:9f:ac:67:28:c2:42:2d:37:16:58:4d.
Are you sure you want to continue connecting (yes/no)?

上面的信息说的是:无法确认主机ssh-server.example.com(192.168.3.9)的真实性,不过知道它的公钥指纹,是否继续连接?
如果输入yes 后,会出现下面信息:

Warning: Permanently added 'ssh-server.example.com,192.168.3.9' (RSA) to the list of known hosts. 
Password: (enter password)

默认密码:alpine
终端执行命令:pwd

/var/root
2.1.2、mobile 登录

$ssh mobile@192.168.31.231
终端执行命令:pwd

/var/mobile
2.1.3、修改用户密码

ROOT 用户可以修改所有用户的密码
输入命令 $passwd mobile 来修改密码

2.1.4、对比电脑手机公钥

mac 电脑
cd .ssh && ls -a

id_rsa      id_rsa.pub  known_hosts

cat known_hosts

192.168.3.9 ssh-rsa AAAAB3NzaC...

iphone 手机
cd /etc/ssh && ls -a

./  ../  moduli  ssh_config  ssh_host_dsa_key  ssh_host_dsa_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub  sshd_config

cat ssh_host_rsa_key.pub

AAAAB3NzaC...

2、USB连接

1、查看 macusb 连接命令

open /System/Library/PrivateFrameworks/MobileDevice.framework/Resources

usbmuxd
2、打开 usb 端口

ssh -p 22 root@192.168.3.9 用端口22进行连接
1、用脚本 tcprelay.py登录
python tcprelay.py -t 22:12345

╰$ python tcprelay.py -t 22:12345 
Forwarding local port 12345 to remote port 22

22端口和12345端口形成映射
2、重新打开窗口,使用12345端口登录
SSH 登录本地电脑建立的服务
ssh -p 12345 root@localhost

The authenticity of host '[localhost]:12345 ([127.0.0.1]:12345)' can't be established.
RSA key fingerprint is SHA256:WS8FONoHfe/MWC6cePdzSFJ6tFLRt5zu2MeCLCSCELo.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: 192.168.3.9
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[localhost]:12345' (RSA) to the list of known hosts.
Enter passphrase for key '/Users/shiji/.ssh/id_rsa': 
shijiteki-iPhone:~ root# 

3、brew install libimobiledevice

相关文章

网友评论

      本文标题:[iOS逆向]17、SSH

      本文链接:https://www.haomeiwen.com/subject/sucohrtx.html