> For the complete documentation index, see [llms.txt](https://krjaeh0.gitbook.io/j-log/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krjaeh0.gitbook.io/j-log/security/dvwa/file_upload.md).

# File\_Upload

* 업로드 되는 파일에 대한 검증이 없기에 파일 업로드에 취약점이 발생한다.

## medium

* JPEG PNG 파일만 올릴 수 있다고 한다.
* [MIME](broken://pages/2e21c564c5d4836ad107bbededbedf7fd4b5a0e0) 라고 하는데 브라우저가 확장자를 인식할 수 있도록 개발자가 관리하는 내용에 의해 파일을 인식한다.
* MIME를 속인다면 원하는 파일을 업로드 할 수 있을 것 같다.
* 확장자가 바뀌어도 코드는 유지된다.
* 업로드 되었다.
* 이렇게 명령어를 넣으면 실행할 수 있을까?
* 실행은 안된다.
* 프록시를 사용하면 실행할 수 있을 것 같다.

### 업로드 과정에서 파일명을 변경해 업로드하기 (프록시 활용)

{% stepper %}
{% step %}

### 인터셉트 및 파일명 변경

* 파일을 업로드할 때 intercept 된 내용이다.
* 파일 이름을 .php로 바꾼다.
  {% endstep %}

{% step %}

### 패킷 전달 및 업로드

* 이후 패킷을 전달하면 파일이름이 바뀌어 업로드 된다.
* 업로드 타입은 MIME 에서 정의되기 때문에 사용자가 임의로 확장자만 맞춰서 업로드하는 것은 막을 수 없다.
  {% endstep %}
  {% endstepper %}

## Hight

* 버퍼에서 파일 이름을 변경해도 업로드 되지 않는다.
* uploaded\_ext: 파일의 확장자
* 확장자를 명확하게 지정해서 업로드 시 .php 같이 명칭을 바꾸는 것이 불가능해 졌다.
* 하지만 [메타 데이터](broken://pages/91cbb647c0e3599b478d79015c25650f8f9f1138)를 수정해서 업로드 하면 우회할 수 있을 것 같은데??

### 메타데이터 기반 우회 시도

* 아무 이미지를 다운로드 받는다.
* 다운받은 이미지는 업로드가 가능한 것을 확인
* exif tool 설치
* [exiftool](broken://pages/3186aa204669fa0b7779da8400be032707c1ecdc) 파일경로 > 메타데이터 확인 가능

## impossible

* 사용자 1회성 토큰을 활용해 우회가 어렵게 만들었다.
* 업로드 취약점 외 다른 취약점을 활용하면 공략이 가능할 것 같다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://krjaeh0.gitbook.io/j-log/security/dvwa/file_upload.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
