Skip to content

Instantly share code, notes, and snippets.

@0xswitch
Created June 3, 2018 21:00
Show Gist options
  • Save 0xswitch/8d70bbbb44eb00cd5d3c20d519263209 to your computer and use it in GitHub Desktop.
Save 0xswitch/8d70bbbb44eb00cd5d3c20d519263209 to your computer and use it in GitHub Desktop.
milnetv2.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define BUFFER_SIZE 512
void print_image()
{
char buffer[BUFFER_SIZE];
FILE* fp = fopen("banner.ascii","r");
if(fp != NULL)
{
while((fgets(buffer,BUFFER_SIZE,fp)) != NULL)
printf("%s", buffer);
fclose(fp);
}else
{
printf("[!] Error file not found: login_image.ascii\n");
exit(-1);
}
}
void read_flag(char* flag)
{
FILE* fd = fopen(".passwd","r");
if(fd == NULL)
{
printf("[!] Error file not found: .passwd\n");
exit(-1);
}
else
{
fgets(flag,32,fd);
fclose(fd);
}
}
int main(int argc,char** argv)
{
int logged;
char username[32];
char password[32];
char flag[32];
char* p;
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stdin, NULL, _IONBF, 0);
read_flag(flag);
print_image();
while(1)
{
memset(username,'\0',32);
memset(password,'\0',32);
printf("Enter username : ");
fgets(username,32,stdin);
printf("Enter password : ");
fgets(password,32,stdin);
p = strstr(username,"\n");
if(p != NULL) *p = 0;
p = strstr(password,"\n");
if(p != NULL) *p = 0;
if(strcmp(username,"exit") == 0)
exit(0);
logged = strcmp(password,flag);
printf("[LOG] username:%s\n",username);
printf("[LOG] entered password:%s\n",password);
printf("[LOG] logged:%d\n",logged);
if(logged == 0)
{
printf("###### Welcome %s\n",username);
execl("/bin/sh","/bin/sh",NULL);
}
else
printf("----------------------[ ACCESS DENIED ]--------------------------\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment