'2019/05'에 해당되는 글 2건

반응형
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

int main() {
	uint64_t *arr[5] = { NULL, };

	for(int i = 0; i < 5; i++){
		arr[i] = (uint64_t *)malloc(0x70);
		printf("arr[%d]: %p\n", i, arr[i]);
	}

	/*
	tcache bypass
	*/
	void *ptr[7] = { NULL, };
	void *ptr2[7] = { NULL, };
	for(int i = 0; i < 7; i++)
		ptr[i] = malloc(0x70);
	for(int i = 0; i < 7; i++)
		ptr2[i] = malloc(0xf0);

	for(int i = 0; i < 7; i++) {
		free(ptr[i]);
		free(ptr2[i]);
	}

	free(arr[3]);

	*(arr[1] - 1) = 0x101;
	free(arr[1]);

	*(arr[3] - 2) = 0x100;
	*(arr[3] - 1) &= -2;

	void *ptra = malloc(224);
	printf("ptr: %p\n", ptra);

	return 0;
}

 

tcache를 사용하지 않는 버전에서는 tcache bypass 부분을 제외하고 생각하면 된다.

 

이 기법은 아래대로 진행된다.

 

0. overlapping될 청크의 바로 다음 청크를 해제

1. 병합할 주소의 size에 값을 overlapping될 청크의 크기 + 현재 크기를 덮은 뒤 해제

2. overlapping될 청크의 바로 다음 청크의 prev_size, size를 덮음 (prev_inuse 제거)

 

'공부' 카테고리의 다른 글

Fuzzing paper  (0) 2021.03.02
stdin, stdout시 동적할당  (0) 2019.07.11
[nodejs] mongoose를 이용한 로그인 구현  (0) 2019.05.08
xss payload  (0) 2019.04.19
[Windows Kernel Driver] 개발환경 구성  (0) 2018.11.25
블로그 이미지

KuroNeko_

KuroNeko

,
반응형
const express = require("express");
const mongoose = require("mongoose");
const bodyparser = require("body-parser");

const app = express();

app.use(bodyparser.urlencoded({	extended: true }));
app.use(express.static("public"));

mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost/test", { useNewUrlParser: true })
	.then(() => console.log("connected mongoose"))
	.catch(e => console.log(e));

const db = mongoose.connection;
var UserScheme = mongoose.Schema({
	username: String,
	password: String
});
var User = mongoose.model("User", UserScheme);

app.get("/setadmin", (req, res) => {
	var admin = new User({ username: "admin", password: "admin" });
	admin.save((err, result) => {});
	res.send("Done");
});

app.get("/list", (req, res) => {
	User.find({}, (err, docs) => {
		res.send(docs);
	});
});

app.get("/", (req, res) => {
	res.send(`
	<html>
	<body>
		<form action="/login" method="POST">
			<input type="text" name="username">
			<input type="text" name="password">
			<input type="submit" value="login">
		</form>
	</body>
	</html>
	`);
});

app.post("/login", (req, res) => {
	var username = req.body.username;
	var password = req.body.password;

	console.log(username, password);
	console.log(typeof username, typeof password);
	if(typeof username !== "string" || typeof password !== "string") {
		res.send("login failed");
		return;
	}

	User.findOne({ username: username, password: password }).exec((err, result) => {
		if(result){
			res.send(`hello ${username}`);
		} else {
			res.send("login failed");
		}
	});
});

app.listen(3000);

자다가 배고파서 라면먹고 nodejs 공부나 해야겠다 싶어서 구글링 해가면서 20분만에 짠 코드

 

typeof를 사용해서 string 체크하는 방식으로 nosql injection을 막아봄.

 

 

'공부' 카테고리의 다른 글

stdin, stdout시 동적할당  (0) 2019.07.11
[how2heap] overlapping_chunks2  (0) 2019.05.22
xss payload  (0) 2019.04.19
[Windows Kernel Driver] 개발환경 구성  (0) 2018.11.25
유저 영역 Stack Canary 분석  (2) 2018.08.16
블로그 이미지

KuroNeko_

KuroNeko

,