// UAFv1.cpp : 定义控制台应用程序的入口点。
//
#include<iostream>
using namespace std;
#include "stdafx.h"
#include<stdio.h>
#include<Windows.h>
#define size 32
class Base
{
public :
int base;
virtual void f(){ cout<<"Base::f()"<<endl;}
virtual void g(){cout<<"Base::g()"<<endl;}
virtual void h(){cout<<"Base::h()"<<endl;}
};
class Child:public Base
{
public:
int child;
void f(){cout<<"Child::f()"<<endl;}
void g1(){cout<<"Child::g1()"<<endl;}
void h1(){cout<<"Child::h1()"<<endl;}
};
int _tmain(int argc, _TCHAR* argv[])
{
char *buf1;
char * buf2;
//Lab1
buf1=(char *)malloc(size);
printf("buf1:0x%pn",buf1);
free(buf1);
buf2=(char *)malloc(size);
printf("buf2:0x%pn",buf2);
memset(buf2,0,size);
printf("buf2:%dn",*buf2);
printf("====Use Afrer Free====n");
strncpy(buf1,"hack",5);
printf("buf2:%snn",buf2);
free(buf2);
//Lab2
Base *B=new Base();
Base *C=new Child();
getchar();
return 0;
}
text:004117C3 mov eax, [ebp+var_8]
.text:004117C6 mov dword ptr [eax], offset ??_7Base@@6B@ ; const Base::`vftable'
通过PWN题掌握UAF
$ scp -P2222 uaf@pwnable.kr:/home/uaf/uaf /Users/p0kerface/
$ scp -P2222 [email protected]:/home/uaf/uaf.cpp /Users/p0kerface/
uaf.cpp
#include <fcntl.h>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
using namespace std;
class Human{
private:
virtual void give_shell(){
system("/bin/sh");
}
protected:
int age;
string name;
public:
virtual void introduce(){
cout << "My name is " << name << endl;
cout << "I am " << age << " years old" << endl;
}
};
class Man: public Human{
public:
Man(string name, int age){
this->name = name;
this->age = age;
}
virtual void introduce(){
Human::introduce();
cout << "I am a nice guy!" << endl;
}
};
class Woman: public Human{
public:
Woman(string name, int age){
this->name = name;
this->age = age;
}
virtual void introduce(){
Human::introduce();
cout << "I am a cute girl!" << endl;
}
};
int main(int argc, char* argv[]){
Human* m = new Man("Jack", 25);
Human* w = new Woman("Jill", 21);
size_t len;
char* data;
unsigned int op;
while(1){
cout << "1. usen2. aftern3. freen";
cin >> op;
switch(op){
case 1:
m->introduce();
w->introduce();
break;
case 2:
len = atoi(argv[1]);
data = new char[len];
read(open(argv[2], O_RDONLY), data, len);
cout << "your data is allocated" << endl;
break;
case 3:
delete m;
delete w;
break;
default:
break;
}
}
return 0;
}
case 1:
m->introduce();
w->introduce();
break;
gdb-peda$ b *0x400f13
Breakpoint 1 at 0x400f13
gdb-peda$ b *0x400fcd
Breakpoint 2 at 0x400fcd
gdb-peda$ b *0x40102d
Breakpoint 3 at 0x40102d
gdb-peda$ b *0x401076
Breakpoint 4 at 0x401076
- 结尾 - 精彩推荐 【技术分享】从Mimikatz 解读windows 下的协议 【技术分享】CVE-2020-8835 pwn2own 2020 ebpf 提权漏洞分析 【技术分享】解决第一个UEFI PWN——Accessing the Truth解题思路 戳“阅读原文”查看更多内容 原文始发于微信公众号(安全客):【技术分享】学习笔记:UAF释放后重用
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论