Memory

我可以從 Tomcat 的記憶體中提取私鑰嗎?

  • April 26, 2016

我正在執行 Tomcat 6。我在搞亂我的密鑰庫以嘗試修復一些證書鏈問題,並且我不小心rm使用了生產版本而不是.new我正在使用的文件。

現在,Tomcat 仍在執行並且仍然能夠提供 HTTPS 連接(我在 Web 瀏覽器中對其進行了測試)。顯然,必須有它仍然可以訪問的私鑰的副本。我的第一個想法是檢查/proc/PID/fd,所以我跑了sudo lsof | grep tomcat。這會正確返回打開文件的列表:

$ sudo lsof | head -1; sudo lsof | grep tomcat
COMMAND     PID     USER   FD      TYPE             DEVICE  SIZE/OFF       NODE NAME
java       2599     root  cwd       DIR              202,1      4096     413699 /usr/share/apache-tomcat-6.0.44/bin
java       2599     root  mem       REG              202,1     51715     413777 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-fr.jar
java       2599     root  mem       REG              202,1    528303     413771 /usr/share/apache-tomcat-6.0.44/lib/jasper.jar
java       2599     root  mem       REG              202,1   1250454     413767 /usr/share/apache-tomcat-6.0.44/lib/catalina.jar
java       2599     root  mem       REG              202,1    132216     413765 /usr/share/apache-tomcat-6.0.44/lib/catalina-ha.jar
java       2599     root  mem       REG              202,1     54334     413778 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-ja.jar
java       2599     root  mem       REG              202,1   1830791     413768 /usr/share/apache-tomcat-6.0.44/lib/ecj-4.3.1.jar
java       2599     root  mem       REG              202,1     54624     413764 /usr/share/apache-tomcat-6.0.44/lib/catalina-ant.jar
java       2599     root  mem       REG              202,1     70563     413776 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-es.jar
java       2599     root  mem       REG              202,1    112521     413770 /usr/share/apache-tomcat-6.0.44/lib/jasper-el.jar
java       2599     root  mem       REG              202,1     76649     413772 /usr/share/apache-tomcat-6.0.44/lib/jsp-api.jar
java       2599     root  mem       REG              202,1     34622     413769 /usr/share/apache-tomcat-6.0.44/lib/el-api.jar
java       2599     root  mem       REG              202,1    253635     413775 /usr/share/apache-tomcat-6.0.44/lib/tomcat-dbcp.jar
java       2599     root  mem       REG              202,1     15250     413763 /usr/share/apache-tomcat-6.0.44/lib/annotations-api.jar
java       2599     root  mem       REG              202,1    801374     413774 /usr/share/apache-tomcat-6.0.44/lib/tomcat-coyote.jar
java       2599     root  mem       REG              202,1    239165     413766 /usr/share/apache-tomcat-6.0.44/lib/catalina-tribes.jar
java       2599     root  mem       REG              202,1    132240     413773 /usr/share/apache-tomcat-6.0.44/lib/servlet-api.jar
java       2599     root  mem       REG              202,1     32384     413759 /usr/share/apache-tomcat-6.0.44/bin/tomcat-juli.jar
java       2599     root  mem       REG              202,1     24283     413753 /usr/share/apache-tomcat-6.0.44/bin/commons-daemon.jar
java       2599     root  mem       REG              202,1     22807     413749 /usr/share/apache-tomcat-6.0.44/bin/bootstrap.jar
java       2599     root    1w      REG              202,1  17024956     413713 /usr/share/apache-tomcat-6.0.44/logs/catalina.out
java       2599     root    2w      REG              202,1  17024956     413713 /usr/share/apache-tomcat-6.0.44/logs/catalina.out
java       2599     root    4r      REG              202,1     22807     413749 /usr/share/apache-tomcat-6.0.44/bin/bootstrap.jar
java       2599     root    5r      REG              202,1     24283     413753 /usr/share/apache-tomcat-6.0.44/bin/commons-daemon.jar
java       2599     root    6r      REG              202,1     32384     413759 /usr/share/apache-tomcat-6.0.44/bin/tomcat-juli.jar
java       2599     root    7w      REG              202,1      4072     396419 /usr/share/apache-tomcat-6.0.44/logs/catalina.2016-04-21.log
java       2599     root    8w      REG              202,1      1182     396447 /usr/share/apache-tomcat-6.0.44/logs/localhost.2016-04-21.log
java       2599     root    9w      REG              202,1         0     396448 /usr/share/apache-tomcat-6.0.44/logs/manager.2016-04-21.log
java       2599     root   10w      REG              202,1         0     396455 /usr/share/apache-tomcat-6.0.44/logs/host-manager.2016-04-21.log
java       2599     root   11r      REG              202,1    239165     413766 /usr/share/apache-tomcat-6.0.44/lib/catalina-tribes.jar
java       2599     root   12r      REG              202,1    801374     413774 /usr/share/apache-tomcat-6.0.44/lib/tomcat-coyote.jar
java       2599     root   13r      REG              202,1    253635     413775 /usr/share/apache-tomcat-6.0.44/lib/tomcat-dbcp.jar
java       2599     root   14r      REG              202,1    132240     413773 /usr/share/apache-tomcat-6.0.44/lib/servlet-api.jar
java       2599     root   15r      REG              202,1     34622     413769 /usr/share/apache-tomcat-6.0.44/lib/el-api.jar
java       2599     root   16r      REG              202,1     76649     413772 /usr/share/apache-tomcat-6.0.44/lib/jsp-api.jar
java       2599     root   17r      REG              202,1    112521     413770 /usr/share/apache-tomcat-6.0.44/lib/jasper-el.jar
java       2599     root   18r      REG              202,1     70563     413776 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-es.jar
java       2599     root   19r      REG              202,1     54624     413764 /usr/share/apache-tomcat-6.0.44/lib/catalina-ant.jar
java       2599     root   20r      REG              202,1   1830791     413768 /usr/share/apache-tomcat-6.0.44/lib/ecj-4.3.1.jar
java       2599     root   21r      REG              202,1     54334     413778 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-ja.jar
java       2599     root   22r      REG              202,1     15250     413763 /usr/share/apache-tomcat-6.0.44/lib/annotations-api.jar
java       2599     root   23r      REG              202,1    132216     413765 /usr/share/apache-tomcat-6.0.44/lib/catalina-ha.jar
java       2599     root   24r      REG              202,1   1250454     413767 /usr/share/apache-tomcat-6.0.44/lib/catalina.jar
java       2599     root   25r      REG              202,1    528303     413771 /usr/share/apache-tomcat-6.0.44/lib/jasper.jar
java       2599     root   26r      REG              202,1     51715     413777 /usr/share/apache-tomcat-6.0.44/lib/tomcat-i18n-fr.jar
bash      29579 ec2-user  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
sudo      30595     root  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
grep      30596 ec2-user  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
lsof      30597     root  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf
lsof      30598     root  cwd       DIR              202,1      4096     413708 /usr/share/apache-tomcat-6.0.44/conf

但不幸的是,我的密鑰庫不是其中之一。我猜 Tomcat 一定已經將它載入到記憶體中,然後關閉了文件描述符。(密鑰庫在/conf上面,但這些文件描述符來自我打開的 shell,而不是來自 Tomcat 本身。)

那麼:有沒有辦法恢復我的私鑰?我在亞馬遜 Linux 上;uname -a返回Linux ip-10-0-0-105 4.4.5-15.26.amzn1.x86_64 #1 SMP Wed Mar 16 17:15:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

您可以嘗試使用passe-partout

我已經成功地將它與 Apache 一起使用,而不是與 Tomcat 一起使用,但它被宣傳為與 Tomcat 7.0.34 + apr 1.4.6 + jdk7-openjdk 7.u9 一起使用。

引用自:https://serverfault.com/questions/773114