免费使用 - 示例

逆向工程 调试 开发 漏洞分析
2021-06-12 11:23:56

这些天使用 After Free错误变得越来越严重。

我计划使用VTable overwrite演示 Use After Free 漏洞利用所以,我正在尝试创建一个ATL ActiveX 控件,它容易受到使用Internet Explorer 9 或 10 的Use After Free 错误的影响

我很难想出一个可用的免费使用后易受攻击的代码有没有人有这种错误的经验,任何人都可以尝试帮助我。

我也在努力 如果我能够让它工作,我会在这里分享:

class User
{
  public:
    virtual void SetUsername() { }
};

class NewUser:public User
{
  char username[20];
  public:
    virtual void SetUserName(char* strUsername) { strcpy(username, strUsername); }
    virtual char* GetUserName() { return username; }
};

STDMETHODIMP CATLActivexControl::CreateUser(BSTR sUserName, DOUBLE* retVal)
{
  USES_CONVERSION;
  char *tmp = W2A(sUserName);
  NewUser *nuser = new NewUser;
  nuser->SetUserName(tmp);

  free(nuser);

  char *xyz = nuser->GetUserNameW();
  return S_OK;
}

我研究了上面的例子,我想出了一个更好的解决方案,它真正触发了“免费使用”。

C++代码

#include "stdafx.h"
#include "ATLStudentActiveXControl.h"

// Virtual Function defination
class User
{
public:
    virtual void Add(char* uName) = 0;
    virtual char* GetName() = 0;
};

class Student : public User
{
private:
    char s_name[30];

public:
    virtual void Add(char* uName) { strncpy(s_name, uName, sizeof(s_name)); }
    virtual char* GetName() { return s_name; }

};

Student *pStudent = new Student;

STDMETHODIMP CATLStudentActiveXControl::Add(BSTR sName)
{
    USES_CONVERSION;
    char *tStudent = W2A(sName);
    pStudent->Add(tStudent);
    return S_OK;
}

STDMETHODIMP CATLStudentActiveXControl::Delete()
{
    free(pStudent);
    return S_OK;
}

STDMETHODIMP CATLStudentActiveXControl::GetName(BSTR* sName)
{
    char *tStudent = pStudent->GetName();
    *sName = A2WBSTR(tStudent);
    return S_OK;
}

HTML代码

<HTML>
<HEAD>
<TITLE>Use After Free - Test Page</TITLE>
<script language="javascript" type="text/javascript">
    function UAF() {
        alert('Start');

        // Assign _studentActiveX variable to ATLStudentActiveXControl
        var _studentActiveX = document.getElementById("ATLStudentActiveXControl");

        // Add a student
        _studentActiveX.Add("StudentName");

        // Uncomment the below line to trigger Use After Free vulnerability
        // _studentActiveX.Delete();

        // Get the name of the added student
        var _studentName = _studentActiveX.GetName();
        alert(_studentName);

        // Delete the student
        _studentActiveX.Delete()

        alert('Done');
    }
</script>
</HEAD>
<BODY>
<OBJECT ID="ATLStudentActiveXControl" CLASSID="CLSID:9EACDFCF-1A2E-462E-9DF6-53E03936DB22"></OBJECT>
<div>
    <p>Demonstrating <b>Use After Free</b> vulnerability.</p>
    <input type="button" onclick="UAF();" value="Use After Free" />
</div>
</BODY>
</HTML>

请分享您的看法。谢谢。

1个回答

我想到的第一件事是让您创建一个包含一些虚拟方法的类,将其用作测试主题。然后从您的 ActiveX 控件中公开操作变量的方法,例如:

  • 方法#1:分配测试对象并将指针保存在静态变量中
  • 方法#2:调用测试对象提供的虚方法
  • 方法#3:释放测试对象实例,不将指针设置为NULL
  • 一些分配其他东西的方法,这些东西可以重用前一种方法中释放的内存

然后编写一个执行给定方法的基本脚本:分配,调用方法以确保它按设计工作,释放实例,分配其他东西,再次调用虚拟方法并使 IE 实例崩溃。;-) 应该可以解决问题。