I have been looking for this for a long time.
I need to extract and get the modulus and the exponent from an SSH server.
For example, I know, that SSH is running on server xxx.xxx.xxx.xxx (I can connect to this server / ping) but I don't know the user name and the password so I cannot log in.
I need to get the modulus and the exponent of the public RSA key of this server.
I found out, that ssh-keyscan
can get modulus + exponent (from documentation) but only if ssh-rsa1 is used. If I try to get ssh-rsa(2) public key with ssh-keyscan, I cannot retrieve the modulus and the exponent from the output.
Is it possible?
use $ sudo chmod 600 ~/. ssh/id_rsa and enter your root credentials to restrict it, then you can output the public key file.
Sure you can!
Download public key from github and save it into github.pub file:
ssh-keyscan -t rsa github.com | sed "s/^[^ ]* //" > github.pub
Convert SSH public key format into X.509 public key format:
ssh-keygen -f github.pub -e -m pem > github.pem
Parse ASN.1 encoding of key to obtain public key modulus and exponent:
sed "/--/d" github.pem | openssl asn1parse | grep "INTEGER" | sed "s/.*://"
Result:
AB603B8511A67679BDB540DB3BD2034B004AE936D06BE3D760F08FCBAADB4EB4EDC3B3C791C70AAE9A74C95869E4774421C2ABEA92E554305F38B5FD414B3208E574C337E320936518462C7652C98B31E16E7DA6523BD200742A6444D83FCD5E1732D03673C7B7811555487B55F0C4494F3829ECE60F94255A95CB9AF537D7FC8C7FE49EF318474EF2920992052265B0A06EA66D4A167FD9F3A48A1A4A307EC1EAAA5149A969A6AC5D56A5EF627E517D81FB644F5B745C4F478ECD082A9492F744AAD326F76C8C4DC9100BC6AB79461D2657CB6F06DEC92E6B64A6562FF0E32084EA06CE0EA9D35A583BFB00BAD38C9D19703C549892E5AA78DC95E250514069
23
First line is a modulus and second line is an exponent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With