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개
잘봤습니다.
오 이런 케이스도 있군요. 대단합니다.
와 대단하십니다.
훌륭한 아이디어입니다.
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5276 | 2년 전 | 1338 | |||
| 5275 | 2년 전 | 1406 | |||
| 5274 | 기타 | 2년 전 | 825 | ||
| 5273 | JavaScript |
swallow
|
2년 전 | 1056 | |
| 5272 | node.js |
swallow
|
2년 전 | 750 | |
| 5271 | JavaScript |
swallow
|
2년 전 | 1503 | |
| 5270 | PHP |
swallow
|
2년 전 | 851 | |
| 5269 | node.js |
swallow
|
2년 전 | 689 | |
| 5268 | node.js |
swallow
|
2년 전 | 1220 | |
| 5267 | PHP |
swallow
|
2년 전 | 1601 | |
| 5266 | MySQL |
swallow
|
2년 전 | 1097 | |
| 5265 | PHP |
swallow
|
2년 전 | 2038 | |
| 5264 | JavaScript |
swallow
|
2년 전 | 863 | |
| 5263 | 기타 |
swallow
|
2년 전 | 2986 | |
| 5262 | 기타 |
swallow
|
2년 전 | 671 | |
| 5261 | node.js |
swallow
|
2년 전 | 1066 | |
| 5260 | JavaScript |
swallow
|
2년 전 | 1514 | |
| 5259 | node.js |
swallow
|
2년 전 | 737 | |
| 5258 | node.js |
swallow
|
2년 전 | 1750 | |
| 5257 | node.js |
swallow
|
2년 전 | 1303 | |
| 5256 | PHP |
swallow
|
2년 전 | 1942 | |
| 5255 | node.js |
swallow
|
2년 전 | 692 | |
| 5254 | PHP |
swallow
|
2년 전 | 3021 | |
| 5253 | node.js |
swallow
|
2년 전 | 683 | |
| 5252 | 정규표현식 |
swallow
|
2년 전 | 625 | |
| 5251 | node.js |
swallow
|
2년 전 | 884 | |
| 5250 | PHP |
swallow
|
2년 전 | 1117 | |
| 5249 | node.js |
swallow
|
2년 전 | 1066 | |
| 5248 | PHP |
swallow
|
2년 전 | 1414 | |
| 5247 | node.js |
swallow
|
2년 전 | 1022 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기