PHP가 없는 환경에서 PHP 라이브러리 호출하기
특수한 경우에 한하지만, PHP가 없는 환경에서 기존 환경을 최대한 해치지 않고 PHP 라이브러리를 호출하는 최선의 방법을 고민하며 나온 결과물을 공유해봅니다.
사용 예시:
> set target https://public-api.example.org
> set method relay_invoke_method
method(relay_invoke_method)> set requires https://raw.githubusercontent.com/dimamedia/PHP-Simple-TOTP-and-PubKey/refs/heads/master/class.tfa.php
method(relay_invoke_method)> show env
{
"target": "https://public-api.example.org",
"method": "relay_invoke_method",
"filename": null,
"requires": [
]
}
method(relay_invoke_method)> do load_script "$tfa = new tfa(); return $tfa->getPubKey()"
RESB 4Y24 3U2K OA2W
method(relay_invoke_method)> do load_script "$tfa = new tfa(); return $tfa->getOtp('RESB 4Y24 3U2K OA2W')"
174053
method(relay_invoke_method)>
서버에 "class.tfa.php"라는 클래스 파일을 전혀 업로드하지 않았으나, 깃허브(또는 공개된 URL)에서 호스팅되고 있는 PHP 파일 주소를 입력하는 것만으로도 바로 불러와서 라이브러리로 활용한 사례입니다.
사용 방법:
1. JSON-RPC 2.0 형식을 해석하고 명령 수행이 가능한 PHP 스크립트를 내려받고 서버에 올린다.
https://github.com/gnh1201/caterpillar/blob/main/assets/php/index.php
2. 사용 예시의 실제 메시지는 다음과 같다. 스크립트가 있는 위치에 POST 요청을 보내어 사용할 수 있다.
요청 예시:
{
"jsonrpc": "2.0",
"method": "relay_invoke_method",
"params": {
"callback": "load_script",
"requires": [
"https://raw.githubusercontent.com/dimamedia/PHP-Simple-TOTP-and-PubKey/refs/heads/master/class.tfa.php"
],
"args": [
"$tfa = new tfa(); return $tfa->getPubKey()"
]
},
"id": null
}
응답 예시:
{
"jsonrpc": "2.0",
"result": {
"status": 200,
"data": "B7FJ 43QC 7WCX CLAY"
},
"id": null,
"_execution_time": 0.017116069793701
}
보안 정책만 잘 조정하여 사용할 수 있다면 특수한 경우에 유용할 것으로 보입니다.
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기
댓글 4개
잘봤습니다.
오 이런 케이스도 있군요. 대단합니다.
와 대단하십니다.
훌륭한 아이디어입니다.