chore: Makefile
This commit is contained in:
parent
270479ced3
commit
e487bff7ac
|
@ -1,7 +1,3 @@
|
|||
*.o
|
||||
*.a
|
||||
woody_woodpacker
|
||||
woody
|
||||
asm
|
||||
payload
|
||||
print
|
||||
|
|
65
Makefile
65
Makefile
|
@ -1,44 +1,57 @@
|
|||
NAME = woody_woodpacker
|
||||
|
||||
SRCS_PATH = srcs/
|
||||
SRC_FILE = main.c \
|
||||
|
||||
SRCS = $(SRCS_PATH)main.c \
|
||||
$(SRCS_PATH)utils.c \
|
||||
$(SRCS_PATH)payload.c \
|
||||
$(SRCS_PATH)woody32.c \
|
||||
$(SRCS_PATH)woody64.c \
|
||||
$(SRCS_PATH)encrypt.c
|
||||
OBJ_FILE = $(SRC_FILE:.c=.o)
|
||||
|
||||
INC_FILE = woody.h \
|
||||
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
SRC_DIR = src/
|
||||
OBJ_DIR = obj/
|
||||
INC_DIR = inc/
|
||||
SRC = $(addprefix $(SRC_DIR), $(SRC_FILE))
|
||||
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE))
|
||||
INC = $(addprefix $(INC_DIR), $(INC_FILE))
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
|
||||
RM = rm -f
|
||||
LIB = ft_printf/libftprintf.a
|
||||
|
||||
LIBFT_FLAGS = ft_printf/libftprintf.a
|
||||
GREEN = \033[32m
|
||||
RED = \033[31m
|
||||
ORANGE = \033[33m
|
||||
PURPLE = \033[35m
|
||||
CYAN = \033[36m
|
||||
WHITE = \033[0m
|
||||
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
all: $(NAME)
|
||||
|
||||
all: ${NAME}
|
||||
$(NAME): $(OBJ) $(INC)
|
||||
@echo -e "$(PURPLE)[MAKE]$(WHITE) ft_printf"
|
||||
@make --no-print-directory -C ft_printf
|
||||
@$(CC) $(CFLAGS) -I $(INC_DIR) -c $(SRC)
|
||||
@mv $(OBJ_FILE) $(OBJ_DIR)
|
||||
@$(CC) $(CFLAGS) $(OBJ) $(LIB) -o $(NAME)
|
||||
@echo -e "$(GREEN)[OK]$(WHITE) $(NAME)"
|
||||
|
||||
.c.o:
|
||||
${CC} ${INCLUDES} ${DEFINES} ${CFLAGS} -c $< -o $@
|
||||
|
||||
$(NAME): ${OBJS}
|
||||
make -C ft_printf
|
||||
${CC} ${OBJS} ${LIBFT_FLAGS} -o ${NAME}
|
||||
$(OBJ_DIR)%.o: $(SRC_DIR)%.c $(INC)
|
||||
@if [ ! -d ./obj ]; then \
|
||||
mkdir -p ./obj; \
|
||||
fi;
|
||||
@$(CC) $(CFLAGS) -I $(INC_DIR) -o $@ -c $<
|
||||
@echo -e "$(CYAN)[CC]$(WHITE) $<"
|
||||
|
||||
clean:
|
||||
make -C ft_printf clean
|
||||
${RM} ${OBJS}
|
||||
@make --no-print-directory -C ft_printf clean
|
||||
@echo -e "$(ORANGE)[CLEAN]$(WHITE) $(NAME)"
|
||||
@rm -rf $(OBJ_DIR)
|
||||
|
||||
fclean:
|
||||
make -C ft_printf fclean
|
||||
make clean
|
||||
${RM} ${NAME}
|
||||
fclean: clean
|
||||
@make --no-print-directory -C ft_printf fclean
|
||||
@echo -e "$(RED)[DELETE]$(WHITE) $(NAME)"
|
||||
@rm -f $(NAME)
|
||||
|
||||
re: fclean
|
||||
make all
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
5
README
5
README
|
@ -1,5 +0,0 @@
|
|||
Transform payload code in hexa :
|
||||
nasm -f elf64 -o print.o print.s && ld -o print print.o && nasm -f bin -o payload print.s && hexdump -v -e '"\\\x\" 1/1 "%02x"' payload
|
||||
|
||||
To get it in the clipboad directly append :
|
||||
| xclip -sel clip to directly
|
BIN
big_sample
BIN
big_sample
Binary file not shown.
1257
big_sample.hex
1257
big_sample.hex
File diff suppressed because it is too large
Load Diff
|
@ -1,62 +1,63 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2021/01/18 18:08:51 by pbonilla #+# #+# #
|
||||
# Updated: 2021/03/12 12:27:09 by pbonilla ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LIBFT = ./libft/libft.a
|
||||
|
||||
NAME = libftprintf.a
|
||||
|
||||
SRCS_PATH = srcs/
|
||||
SRC_FILE = ft_printf.c \
|
||||
ft_parser.c \
|
||||
ft_int_case.c \
|
||||
ft_char_case.c \
|
||||
ft_str_case.c \
|
||||
ft_ui_case.c \
|
||||
ft_x_case.c \
|
||||
ft_ptr_case.c \
|
||||
ft_percent_case.c \
|
||||
ft_printf_memset.c \
|
||||
|
||||
SRCS = $(SRCS_PATH)ft_printf.c \
|
||||
$(SRCS_PATH)ft_parser.c \
|
||||
$(SRCS_PATH)ft_int_case.c \
|
||||
$(SRCS_PATH)ft_char_case.c \
|
||||
$(SRCS_PATH)ft_str_case.c \
|
||||
$(SRCS_PATH)ft_ui_case.c \
|
||||
$(SRCS_PATH)ft_x_case.c \
|
||||
$(SRCS_PATH)ft_ptr_case.c \
|
||||
$(SRCS_PATH)ft_percent_case.c \
|
||||
$(SRCS_PATH)ft_printf_memset.c \
|
||||
OBJ_FILE = $(SRC_FILE:.c=.o)
|
||||
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
INC_FILE = ft_printf.h \
|
||||
|
||||
SRC_DIR = src/
|
||||
OBJ_DIR = obj/
|
||||
INC_DIR = inc/
|
||||
SRC = $(addprefix $(SRC_DIR), $(SRC_FILE))
|
||||
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE))
|
||||
INC = $(addprefix $(INC_DIR), $(INC_FILE))
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
|
||||
RM = rm -f
|
||||
GREEN = \033[32m
|
||||
RED = \033[31m
|
||||
ORANGE = \033[33m
|
||||
PURPLE = \033[35m
|
||||
CYAN = \033[36m
|
||||
WHITE = \033[0m
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
$(NAME): $(OBJ) $(INC)
|
||||
@echo -e "$(PURPLE)[MAKE]$(WHITE) libft"
|
||||
@make --no-print-directory -C ./libft
|
||||
@cp libft/libft.a $(NAME)
|
||||
@ar -rcs $(NAME) $(OBJ)
|
||||
@ranlib $(NAME)
|
||||
@echo -e "$(GREEN)[OK]$(WHITE) $(NAME)"
|
||||
|
||||
INCLUDES = -I libft
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
.c.o:
|
||||
${CC} ${INCLUDES} ${DEFINES} ${CFLAGS} -c $< -o $@
|
||||
|
||||
$(NAME): ${OBJS}
|
||||
$(MAKE) bonus -C ./libft
|
||||
cp libft/libft.a $(NAME)
|
||||
ar -rcs $(NAME) $(OBJS)
|
||||
ranlib $(NAME)
|
||||
$(OBJ_DIR)%.o: $(SRC_DIR)%.c libft/ $(INC)
|
||||
@if [ ! -d ./obj ]; then \
|
||||
mkdir -p ./obj; \
|
||||
fi;
|
||||
@$(CC) $(CFLAGS) -I $(INC_DIR) -I libft/inc -o $@ -c $<
|
||||
@echo -e "$(CYAN)[CC]$(WHITE) $<"
|
||||
|
||||
clean:
|
||||
$(MAKE) clean -C ./libft
|
||||
${RM} ${OBJS}
|
||||
|
||||
@make --no-print-directory -C libft clean
|
||||
@echo -e "$(ORANGE)[CLEAN]$(WHITE) $(NAME)"
|
||||
@rm -rf $(OBJ_DIR)
|
||||
|
||||
fclean: clean
|
||||
$(MAKE) fclean -C ./libft
|
||||
${RM} ${NAME}
|
||||
@make --no-print-directory -C libft fclean
|
||||
@echo -e "$(RED)[DELETE]$(WHITE) $(NAME)"
|
||||
@rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#ifndef FT_PRINTF_H
|
||||
# define FT_PRINTF_H
|
||||
|
||||
# include "../libft/libft.h"
|
||||
# include "../libft/inc/libft.h"
|
||||
# include <stdarg.h>
|
||||
# include <stdio.h>
|
||||
|
|
@ -1,103 +1,100 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2021/01/18 18:08:51 by pbonilla #+# #+# #
|
||||
# Updated: 2021/02/07 14:20:29 by pbonilla ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
|
||||
SRCS_PATH = ./
|
||||
SRC_FILE = ft_atoi.c \
|
||||
ft_toupper.c \
|
||||
ft_bzero.c \
|
||||
ft_isalnum.c \
|
||||
ft_tolower.c \
|
||||
ft_memcpy.c \
|
||||
ft_memccpy.c \
|
||||
ft_memmove.c \
|
||||
ft_memset.c \
|
||||
ft_memchr.c \
|
||||
ft_memcmp.c \
|
||||
ft_strlcat.c \
|
||||
ft_strnstr.c \
|
||||
ft_strlcat.c \
|
||||
ft_strlen.c \
|
||||
ft_strchr.c \
|
||||
ft_strrchr.c \
|
||||
ft_isalpha.c \
|
||||
ft_isascii.c \
|
||||
ft_strlcpy.c \
|
||||
ft_strncmp.c \
|
||||
ft_isdigit.c \
|
||||
ft_isprint.c \
|
||||
ft_toupper.c \
|
||||
ft_bzero.c \
|
||||
ft_strdup.c \
|
||||
ft_strnstr.c \
|
||||
ft_strnstr_nullterminated.c \
|
||||
ft_calloc.c \
|
||||
ft_substr.c \
|
||||
ft_strjoin.c \
|
||||
ft_u_itoa.c \
|
||||
ft_itoa.c \
|
||||
ft_strmapi.c \
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_strtrim.c \
|
||||
ft_split.c \
|
||||
ft_u_convert.c \
|
||||
ft_convert_base.c \
|
||||
ft_revert_int.c \
|
||||
ft_lstnew.c \
|
||||
ft_lstadd_front.c \
|
||||
ft_lstsize.c \
|
||||
ft_lstlast.c \
|
||||
ft_lstadd_back.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstclear.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
|
||||
SRCS = $(SRCS_PATH)ft_atoi.c \
|
||||
$(SRCS_PATH)ft_toupper.c \
|
||||
$(SRCS_PATH)ft_bzero.c \
|
||||
$(SRCS_PATH)ft_isalnum.c \
|
||||
$(SRCS_PATH)ft_tolower.c \
|
||||
$(SRCS_PATH)ft_memcpy.c \
|
||||
$(SRCS_PATH)ft_memccpy.c \
|
||||
$(SRCS_PATH)ft_memmove.c \
|
||||
$(SRCS_PATH)ft_memset.c \
|
||||
$(SRCS_PATH)ft_memchr.c \
|
||||
$(SRCS_PATH)ft_memcmp.c \
|
||||
$(SRCS_PATH)ft_strlcat.c \
|
||||
$(SRCS_PATH)ft_strnstr.c \
|
||||
$(SRCS_PATH)ft_strlcat.c \
|
||||
$(SRCS_PATH)ft_strlen.c \
|
||||
$(SRCS_PATH)ft_strchr.c \
|
||||
$(SRCS_PATH)ft_strrchr.c \
|
||||
$(SRCS_PATH)ft_isalpha.c \
|
||||
$(SRCS_PATH)ft_isascii.c \
|
||||
$(SRCS_PATH)ft_strlcpy.c \
|
||||
$(SRCS_PATH)ft_strncmp.c \
|
||||
$(SRCS_PATH)ft_isdigit.c \
|
||||
$(SRCS_PATH)ft_isprint.c \
|
||||
$(SRCS_PATH)ft_toupper.c \
|
||||
$(SRCS_PATH)ft_bzero.c \
|
||||
$(SRCS_PATH)ft_strdup.c \
|
||||
$(SRCS_PATH)ft_strnstr.c \
|
||||
$(SRCS_PATH)ft_strnstr_nullterminated.c \
|
||||
$(SRCS_PATH)ft_calloc.c \
|
||||
$(SRCS_PATH)ft_substr.c \
|
||||
$(SRCS_PATH)ft_strjoin.c \
|
||||
$(SRCS_PATH)ft_u_itoa.c \
|
||||
$(SRCS_PATH)ft_itoa.c \
|
||||
$(SRCS_PATH)ft_strmapi.c \
|
||||
$(SRCS_PATH)ft_putchar_fd.c \
|
||||
$(SRCS_PATH)ft_putstr_fd.c \
|
||||
$(SRCS_PATH)ft_putnbr_fd.c \
|
||||
$(SRCS_PATH)ft_putendl_fd.c \
|
||||
$(SRCS_PATH)ft_strtrim.c \
|
||||
$(SRCS_PATH)ft_split.c \
|
||||
$(SRCS_PATH)ft_u_convert.c \
|
||||
$(SRCS_PATH)ft_convert_base.c \
|
||||
$(SRCS_PATH)ft_revert_int.c \
|
||||
OBJ_FILE = $(SRC_FILE:.c=.o)
|
||||
|
||||
INC_FILE = libft.h
|
||||
|
||||
BONUS = $(SRCS_PATH)ft_lstnew.c \
|
||||
$(SRCS_PATH)ft_lstadd_front.c \
|
||||
$(SRCS_PATH)ft_lstsize.c \
|
||||
$(SRCS_PATH)ft_lstlast.c \
|
||||
$(SRCS_PATH)ft_lstadd_back.c \
|
||||
$(SRCS_PATH)ft_lstdelone.c \
|
||||
$(SRCS_PATH)ft_lstclear.c \
|
||||
$(SRCS_PATH)ft_lstiter.c \
|
||||
$(SRCS_PATH)ft_lstmap.c \
|
||||
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
|
||||
BONUS_OBJS = $(BONUS:.c=.o)
|
||||
SRC_DIR = src/
|
||||
OBJ_DIR = obj/
|
||||
INC_DIR = inc/
|
||||
SRC = $(addprefix $(SRC_DIR), $(SRC_FILE))
|
||||
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE))
|
||||
INC = $(addprefix $(INC_DIR), $(INC_FILE))
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
|
||||
RM = rm -f
|
||||
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
ar rc $(NAME) $(OBJS)
|
||||
ranlib $(NAME)
|
||||
GREEN = \033[32m
|
||||
RED = \033[31m
|
||||
ORANGE = \033[33m
|
||||
CYAN = \033[36m
|
||||
WHITE = \033[0m
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
.c.o:
|
||||
${CC} ${INCLUDES} ${DEFINES} ${CFLAGS} -c $< -o $@
|
||||
$(NAME): $(OBJ) $(INC)
|
||||
@ar rc $(NAME) $(OBJ)
|
||||
@ranlib $(NAME)
|
||||
@echo -e "$(GREEN)[OK]$(WHITE) $(NAME)"
|
||||
|
||||
$(OBJ_DIR)%.o: $(SRC_DIR)%.c $(INC)
|
||||
@if [ ! -d ./obj ]; then \
|
||||
mkdir -p ./obj; \
|
||||
fi;
|
||||
@$(CC) $(CFLAGS) -I $(INC_DIR) -o $@ -c $<
|
||||
@echo -e "$(CYAN)[CC]$(WHITE) $<"
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJS) $(BONUS_OBJS)
|
||||
@echo -e "$(ORANGE)[CLEAN]$(WHITE) $(NAME)"
|
||||
@rm -rf $(OBJ_DIR)
|
||||
|
||||
fclean: clean
|
||||
rm -rf $(NAME)
|
||||
@echo -e "$(RED)[DELETE]$(WHITE) $(NAME)"
|
||||
@rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
bonus: $(OBJS) $(BONUS_OBJS)
|
||||
ar rc $(NAME) $(OBJS) $(BONUS_OBJS)
|
||||
ranlib $(NAME)
|
||||
|
||||
.PHONY : all clean fclean re bonus
|
||||
.PHONY: all clean fclean re
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
char *ft_char_case(t_param *param, int i)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
char *fill_s_int(char *s, int len, char *s_i, t_param *param)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
t_param ft_init_param(void)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
char *ft_percent_case(t_param *param)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_print_param(t_param *param, va_list args, char **buff)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
void *ft_printf_memset(void *s, size_t n, t_param *param)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int zero_case(t_param *param, unsigned long long i)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
char *fill_s_str(char *s, int len, char *s_arg, t_param *param)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
char *fill_s_uint(char *s, int len, char *s_ui, t_param *param)
|
||||
{
|
|
@ -10,7 +10,7 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_printf.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
char *fill_s_x(int len, int save, char *s_x, t_param *param)
|
||||
{
|
|
@ -1 +0,0 @@
|
|||
nasm -f elf64 -o print.o print.s && ld -o print print.o && nasm -f bin -o payload print.s && hexdump -v -e '"\\\x\" 1/1 "%02x"' payload
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef WOODY_H
|
||||
# define WOODY_H
|
||||
|
||||
# include "../ft_printf/inc/ft_printf.h"
|
||||
|
||||
#endif
|
|
@ -1,81 +0,0 @@
|
|||
#ifndef WOODY_H
|
||||
#define WOODY_H
|
||||
|
||||
#include "../ft_printf/includes/ft_printf.h"
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <elf.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define JUMP "\xe9"
|
||||
#define WOODY "....WOODY...."
|
||||
#define JUMP_VALUE "\xda\xda\xda"
|
||||
|
||||
#define TEXT_OFFSET "\xba\xba\xba\xba\xba\xba\xba\xba"
|
||||
#define SECTION_SIZE "\xca\xca\xca\xca\xca\xca\xca\xca"
|
||||
|
||||
typedef struct payload
|
||||
{
|
||||
char *payload;
|
||||
int len;
|
||||
} t_payload;
|
||||
|
||||
typedef struct elf32
|
||||
{
|
||||
Elf32_Ehdr *Ehdr;
|
||||
Elf32_Phdr *Phdr;
|
||||
Elf32_Shdr *Shdr;
|
||||
Elf32_Shdr *text_section;
|
||||
} t_elf32;
|
||||
|
||||
typedef struct elf64
|
||||
{
|
||||
Elf64_Ehdr *Ehdr;
|
||||
Elf64_Phdr *Phdr;
|
||||
Elf64_Shdr *Shdr;
|
||||
Elf64_Shdr *text_section;
|
||||
} t_elf64;
|
||||
|
||||
typedef struct elf_content
|
||||
{
|
||||
long unsigned int file_size;
|
||||
char *file_path;
|
||||
char *file;
|
||||
t_elf32 *elf32;
|
||||
t_elf64 *elf64;
|
||||
} t_elf_content;
|
||||
|
||||
// utils.c
|
||||
void *fetch(char *file, unsigned long file_size, unsigned long offset_to_data, unsigned long supposed_data_size);
|
||||
int ft_put_error(char *str);
|
||||
char *get_string(char *str, char *end_file);
|
||||
int get_symbols_count(int sh_size, int sh_entsize);
|
||||
char *get_section_name(t_elf_content *woody, int section_index);
|
||||
int elf_magic_numbers(char *str);
|
||||
|
||||
// payload.c
|
||||
t_payload *get_payload();
|
||||
int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_position, unsigned int e_entry, unsigned int p_offset, unsigned int p_memsz);
|
||||
|
||||
// woody32.c
|
||||
int get_elf_sections32(t_elf_content *woody);
|
||||
int inject32(t_elf_content *woody);
|
||||
|
||||
// woody64.c
|
||||
int get_elf_sections64(t_elf_content *woody);
|
||||
int inject64(t_elf_content *woody);
|
||||
|
||||
|
||||
// encrypt.c
|
||||
void encrypt(char *file, unsigned long int offset, unsigned long int size);
|
||||
|
||||
#endif
|
||||
|
BIN
not_that_big
BIN
not_that_big
Binary file not shown.
1001
not_that_big.hex
1001
not_that_big.hex
File diff suppressed because it is too large
Load Diff
37
print.s
37
print.s
|
@ -1,37 +0,0 @@
|
|||
bits 64
|
||||
global _start
|
||||
|
||||
_start:
|
||||
push rax
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
|
||||
mov rdi, 1
|
||||
lea rsi, [rel msg]
|
||||
mov rax, rsi
|
||||
sub rax, qword [rel text_section] ;text_section address
|
||||
mov r8, qword [rel section_size] ;text_section size
|
||||
mov r9, 0 ;increment register
|
||||
xor r10, r10
|
||||
encrypt:
|
||||
cmp r8, r9
|
||||
je end_encrypt
|
||||
movzx r10, byte[rax + r9]
|
||||
inc r10b ;rot + 1
|
||||
mov byte[rax + r9], r10b
|
||||
inc r9
|
||||
jmp encrypt
|
||||
end_encrypt:
|
||||
mov rdx, 14
|
||||
mov rax, 1
|
||||
syscall
|
||||
pop rdx
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rax
|
||||
|
||||
jmp 0xdadadada
|
||||
msg db "....WOODY....",10
|
||||
text_section dq 0xbabababababababa
|
||||
section_size dq 0xcacacacacacacaca
|
|
@ -1,412 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
printf("Hello, World!\n");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
return (0);
|
||||
}
|
|
@ -1,332 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
printf("Hello, World!\n");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
return (0);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
printf("Hello, World!\n");
|
||||
return (0);
|
||||
int
|
||||
main(void) {
|
||||
ft_printf("Hello, World!\n");
|
||||
return (0x0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#include "woody.h"
|
||||
|
||||
int main(void) {
|
||||
ft_printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#include "../includes/woody.h"
|
||||
|
||||
void encrypt(char *file, unsigned long int offset, unsigned long int size)
|
||||
{
|
||||
size_t i = 0;
|
||||
while (i < size)
|
||||
{
|
||||
file[offset + i] = file[offset + i] - 1;
|
||||
++i;
|
||||
}
|
||||
}
|
127
srcs/main.c
127
srcs/main.c
|
@ -1,127 +0,0 @@
|
|||
#include "../includes/woody.h"
|
||||
|
||||
void free_elf_content(t_elf_content *woody)
|
||||
{
|
||||
if (woody->elf32)
|
||||
free(woody->elf32);
|
||||
else if (woody->elf64)
|
||||
free(woody->elf64);
|
||||
}
|
||||
int get_elf_file(t_elf_content *woody)
|
||||
{
|
||||
int fd;
|
||||
off_t off;
|
||||
|
||||
fd = open(woody->file_path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
ft_printf("Error: Failed to open \'%s\'\n", woody->file_path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
off = lseek(fd, 0, SEEK_END);
|
||||
if (off == -1)
|
||||
{
|
||||
close(fd);
|
||||
ft_printf("Error: Failed to read file offset \'%s\'\n", woody->file_path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
woody->file_size = off;
|
||||
woody->file = mmap(NULL, woody->file_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
|
||||
if (woody->file == MAP_FAILED)
|
||||
{
|
||||
close(fd);
|
||||
ft_printf("Error: Failed to map file \'%s\'\n", woody->file_path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int save_file(char *path, char *file, unsigned long int size)
|
||||
{
|
||||
int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0755);
|
||||
if (fd == -1) {
|
||||
ft_printf("Error: Failed to create new file \'%s\'\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (write(fd, file, size) == -1) {
|
||||
close(fd);
|
||||
ft_printf("Error: Failed to write new file \'%s\'\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int save_woody(t_elf_content *woody)
|
||||
{
|
||||
char *woody_file = malloc(woody->file_size);
|
||||
if (!woody_file)
|
||||
return ft_put_error("Allocation error");
|
||||
ft_memcpy(woody_file, woody->file, woody->file_size);
|
||||
|
||||
if (munmap(woody->file, woody->file_size))
|
||||
return ft_put_error("Umapping error");
|
||||
|
||||
int save_error = save_file("woody", woody_file, woody->file_size);
|
||||
if (save_error)
|
||||
return save_error;
|
||||
free(woody_file);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_elf_content woody = {0};
|
||||
if (ac != 2)
|
||||
{
|
||||
return ft_put_error("Woody_woodpacker take 1 argument\n");
|
||||
}
|
||||
woody.file_path = av[1];
|
||||
int elf_error = get_elf_file(&woody);
|
||||
if (elf_error)
|
||||
return elf_error;
|
||||
if (woody.file_size < sizeof(Elf32_Ehdr) || !elf_magic_numbers(woody.file))
|
||||
{
|
||||
ft_printf("Error: \'%s\' is not a valid ELF file\n", woody.file_path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int elfclass = woody.file[4];
|
||||
if (elfclass == ELFCLASS32)
|
||||
{
|
||||
if (!(woody.elf32 = malloc(sizeof(t_elf32))))
|
||||
return ft_put_error("Allocation error");
|
||||
elf_error = get_elf_sections32(&woody);
|
||||
}
|
||||
else if (elfclass == ELFCLASS64)
|
||||
{
|
||||
if (!(woody.elf64 = malloc(sizeof(t_elf64))))
|
||||
return ft_put_error("Allocation error");
|
||||
elf_error = get_elf_sections64(&woody);
|
||||
}
|
||||
else
|
||||
{
|
||||
elf_error = EXIT_FAILURE;
|
||||
ft_printf("Error: \'%s\' is not a valid ELF file\n", woody.file_path);
|
||||
}
|
||||
if (elf_error)
|
||||
return elf_error;
|
||||
int inject_error = -1;
|
||||
if (elfclass == ELFCLASS32)
|
||||
{
|
||||
inject_error = inject32(&woody);
|
||||
}
|
||||
else if (elfclass == ELFCLASS64)
|
||||
{
|
||||
inject_error = inject64(&woody);
|
||||
}
|
||||
if (inject_error)
|
||||
{
|
||||
free_elf_content(&woody);
|
||||
return inject_error;
|
||||
}
|
||||
int save_error = save_woody(&woody);
|
||||
free_elf_content(&woody);
|
||||
return save_error;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
|
||||
#include "../includes/woody.h"
|
||||
|
||||
t_payload *get_payload()
|
||||
{
|
||||
t_payload *payload = malloc(sizeof(t_payload));
|
||||
if (!payload)
|
||||
return NULL;
|
||||
char buffer[1024];
|
||||
int fd = open("payload", O_RDONLY);
|
||||
if (fd == -1) {
|
||||
ft_put_error("Failed to open payload");
|
||||
free(payload);
|
||||
return NULL;
|
||||
}
|
||||
payload->len = read(fd, buffer, 1024);
|
||||
if (payload->len == -1)
|
||||
{
|
||||
ft_put_error("Failed to read payload");
|
||||
free(payload);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
close(fd);
|
||||
payload->payload = malloc(sizeof(char) * payload->len);
|
||||
if (!payload->payload)
|
||||
{
|
||||
ft_put_error("Allocation error");
|
||||
free(payload);
|
||||
return NULL;
|
||||
}
|
||||
ft_memcpy(payload->payload, buffer, payload->len);
|
||||
return payload;
|
||||
}
|
||||
|
||||
int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_position, unsigned int e_entry, unsigned int p_offset, unsigned int p_memsz)
|
||||
{
|
||||
char *ptr_jmp_value = ft_strnstr_nullterminated(payload->payload, JUMP_VALUE, payload->len);
|
||||
char *ptr_woody = ft_strnstr_nullterminated(payload->payload, WOODY, payload->len);
|
||||
char *ptr_text_section = ft_strnstr_nullterminated(payload->payload, TEXT_OFFSET, payload->len);
|
||||
char *ptr_section_size = ft_strnstr_nullterminated(payload->payload, SECTION_SIZE, payload->len);
|
||||
if (ptr_jmp_value && ptr_woody && ptr_text_section && ptr_section_size)
|
||||
{
|
||||
int32_t woody_index = ptr_woody - payload->payload;
|
||||
int32_t jmp_index = ptr_jmp_value - sizeof(JUMP) - payload->payload;
|
||||
int32_t jump_value = ((payload_position + jmp_index + 5) - e_entry) * -1; // 5 = JUMP SIZE (OPCODE + 4 bytes operand)
|
||||
ft_memcpy(&payload->payload[jmp_index + 1], &jump_value, sizeof(jump_value));
|
||||
|
||||
printf("jump_value = %d (%x)\n", jump_value, jump_value);
|
||||
printf("jmp_index = %d (%x)\n", jmp_index, jmp_index);
|
||||
printf("payload_position = %ld (%lx)\n", payload_position, payload_position);
|
||||
printf("e_entry = %d (%x)\n", e_entry, e_entry);
|
||||
|
||||
int64_t text_index = ptr_text_section - payload->payload;
|
||||
int64_t text_value = payload_position - p_offset + woody_index;
|
||||
ft_memcpy(&payload->payload[text_index], &text_value, sizeof(text_value));
|
||||
|
||||
int64_t section_index = ptr_section_size - payload->payload;
|
||||
int64_t section_value = p_memsz;
|
||||
ft_memcpy(&payload->payload[section_index], §ion_value, sizeof(section_value));
|
||||
|
||||
ft_memcpy(woody->file + payload_position, payload->payload, payload->len);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
40
srcs/utils.c
40
srcs/utils.c
|
@ -1,40 +0,0 @@
|
|||
#include "../includes/woody.h"
|
||||
|
||||
void *fetch(char *file, unsigned long file_size, unsigned long offset_to_data, unsigned long supposed_data_size)
|
||||
{
|
||||
if (file_size > offset_to_data && file_size >= (offset_to_data + supposed_data_size))
|
||||
return (file + offset_to_data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int elf_magic_numbers(char *str)
|
||||
{
|
||||
return (!ft_strncmp(str, ELFMAG, SELFMAG));
|
||||
}
|
||||
|
||||
int get_symbols_count(int sh_size, int sh_entsize)
|
||||
{
|
||||
if (sh_size <= 0 || sh_entsize <= 0)
|
||||
return 0;
|
||||
return (sh_size / sh_entsize);
|
||||
}
|
||||
|
||||
char *get_string(char *str, char *end_file)
|
||||
{
|
||||
char *search_end = str;
|
||||
while (search_end < end_file)
|
||||
{
|
||||
if (*search_end == 0)
|
||||
return str;
|
||||
++search_end;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ft_put_error(char *str)
|
||||
{
|
||||
ft_putstr_fd("Error: ", STDERR_FILENO);
|
||||
ft_putstr_fd(str, 2);
|
||||
ft_putstr_fd("\n", STDERR_FILENO);
|
||||
return EXIT_FAILURE;
|
||||
}
|
106
srcs/woody32.c
106
srcs/woody32.c
|
@ -1,106 +0,0 @@
|
|||
#include "../includes/woody.h"
|
||||
|
||||
int get_load_segment32(t_elf_content *woody, int start, bool executable)
|
||||
{
|
||||
t_elf32 *elf = woody->elf32;
|
||||
for (int i = start; i < elf->Ehdr->e_phnum; i++)
|
||||
{
|
||||
if (elf->Phdr[i].p_type == PT_LOAD)
|
||||
{
|
||||
if (executable)
|
||||
{
|
||||
if (elf->Phdr[i].p_flags & PF_X)
|
||||
return i;
|
||||
}
|
||||
else
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int inject32(t_elf_content *woody)
|
||||
{
|
||||
t_elf32 *elf = woody->elf32;
|
||||
t_payload *payload = get_payload();
|
||||
if (!payload)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
int i = get_load_segment32(woody, 0, true);
|
||||
int j = get_load_segment32(woody, i + 1, false);
|
||||
|
||||
if (i == -1 || j != i + 1)
|
||||
{
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return ft_put_error("PT_LOAD segment missing");
|
||||
}
|
||||
size_t code_cave_size = elf->Phdr[j].p_offset - (elf->Phdr[i].p_offset + elf->Phdr[i].p_filesz);
|
||||
size_t payload_position = elf->Phdr[i].p_offset + elf->Phdr[i].p_filesz;
|
||||
|
||||
if (code_cave_size < (size_t)payload->len)
|
||||
{
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return ft_put_error("Unable to insert payload, not enough space for code cave");
|
||||
}
|
||||
|
||||
encrypt(woody->file, elf->Phdr[i].p_offset, elf->Phdr[i].p_memsz);
|
||||
|
||||
if (insert_payload(woody, payload, payload_position, elf->text_section->sh_offset, elf->Phdr[i].p_offset, elf->Phdr[i].p_memsz))
|
||||
{
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return ft_put_error("Unable to insert payload, please regenerate it");
|
||||
}
|
||||
printf("code_cave_size = %ld (%lx)\n", code_cave_size, code_cave_size);
|
||||
printf("payload_position = %ld (%lx)\n", payload_position, payload_position);
|
||||
printf("elf->Phdr[i].p_offset = %d (%x)\n", elf->Phdr[i].p_offset, elf->Phdr[i].p_offset);
|
||||
printf("elf->Phdr[i].p_filesz = %d (%x)\n", elf->Phdr[i].p_filesz, elf->Phdr[i].p_filesz);
|
||||
printf("elf->Phdr[j].p_offset = %d (%x)\n", elf->Phdr[j].p_offset, elf->Phdr[j].p_offset);
|
||||
|
||||
|
||||
elf->Phdr[i].p_filesz += payload->len;
|
||||
elf->Phdr[i].p_memsz += payload->len;
|
||||
elf->Phdr[i].p_flags = PF_X | PF_W | PF_R;
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int get_elf_sections32(t_elf_content *woody)
|
||||
{
|
||||
t_elf32 *elf = woody->elf32;
|
||||
|
||||
elf->Ehdr = (Elf32_Ehdr *)fetch(woody->file, woody->file_size, 0, sizeof(Elf32_Ehdr));
|
||||
if (!elf->Ehdr)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
elf->Phdr = (Elf32_Phdr *)fetch(woody->file, woody->file_size, elf->Ehdr->e_phoff, sizeof(Elf32_Phdr));
|
||||
if (!elf->Phdr)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
elf->Shdr = (Elf32_Shdr *)fetch(woody->file, woody->file_size, elf->Ehdr->e_shoff, sizeof(Elf32_Shdr));
|
||||
if (!elf->Shdr || !fetch(woody->file, woody->file_size, elf->Ehdr->e_shoff, elf->Ehdr->e_shnum * sizeof(Elf32_Shdr)))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!fetch(woody->file, woody->file_size, elf->Ehdr->e_shoff + (elf->Ehdr->e_shstrndx * sizeof(Elf32_Shdr)), sizeof(Elf32_Shdr)))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
char *Sshstrtab = (char *)fetch(woody->file, woody->file_size, elf->Shdr[elf->Ehdr->e_shstrndx].sh_offset, 0);
|
||||
if (Sshstrtab == NULL)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
for (int i = 0; i < elf->Ehdr->e_shnum;i++)
|
||||
{
|
||||
if (elf->Shdr[i].sh_type == SHT_PROGBITS && elf->Shdr[i].sh_flags & SHF_EXECINSTR && elf->Shdr[i].sh_flags & SHF_ALLOC && elf->Shdr[i].sh_flags & SHF_EXECINSTR)
|
||||
{
|
||||
if (Sshstrtab + elf->Shdr[i].sh_name < (char *)woody->file + woody->file_size && !ft_strncmp(".text\0", Sshstrtab + elf->Shdr[i].sh_name, 6))
|
||||
{
|
||||
elf->text_section = &elf->Shdr[i];
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
101
srcs/woody64.c
101
srcs/woody64.c
|
@ -1,101 +0,0 @@
|
|||
#include "../includes/woody.h"
|
||||
|
||||
int get_load_segment64(t_elf_content *woody, int start, bool executable)
|
||||
{
|
||||
t_elf64 *elf = woody->elf64;
|
||||
for (int i = start; i < elf->Ehdr->e_phnum; i++)
|
||||
{
|
||||
if (elf->Phdr[i].p_type == PT_LOAD)
|
||||
{
|
||||
if (executable)
|
||||
{
|
||||
if (elf->Phdr[i].p_flags & PF_X)
|
||||
return i;
|
||||
}
|
||||
else
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int inject64(t_elf_content *woody)
|
||||
{
|
||||
t_elf64 *elf = woody->elf64;
|
||||
t_payload *payload = get_payload();
|
||||
if (!payload)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
int i = get_load_segment64(woody, 0, true);
|
||||
int j = get_load_segment64(woody, i + 1, false);
|
||||
|
||||
if (i == -1 || j != i + 1)
|
||||
{
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return ft_put_error("PT_LOAD segment missing");
|
||||
}
|
||||
|
||||
size_t code_cave_size = elf->Phdr[j].p_offset - (elf->Phdr[i].p_offset + elf->Phdr[i].p_filesz);
|
||||
size_t payload_position = elf->Phdr[i].p_offset + elf->Phdr[i].p_filesz;
|
||||
|
||||
if (code_cave_size < (size_t)payload->len)
|
||||
{
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return ft_put_error("Unable to insert payload, not enough space for code cave");
|
||||
}
|
||||
encrypt(woody->file, elf->Phdr[i].p_offset, elf->Phdr[i].p_memsz);
|
||||
|
||||
if (insert_payload(woody, payload, payload_position, elf->Ehdr->e_entry, elf->Phdr[i].p_offset, elf->Phdr[i].p_memsz))
|
||||
{
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return ft_put_error("Unable to insert payload, please regenerate it");
|
||||
}
|
||||
|
||||
elf->Ehdr->e_entry = payload_position;
|
||||
elf->Phdr[i].p_filesz += payload->len;
|
||||
elf->Phdr[i].p_memsz += payload->len;
|
||||
elf->Phdr[i].p_flags = PF_X | PF_W | PF_R;
|
||||
free(payload->payload);
|
||||
free(payload);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int get_elf_sections64(t_elf_content *woody)
|
||||
{
|
||||
t_elf64 *elf = woody->elf64;
|
||||
|
||||
elf->Ehdr = (Elf64_Ehdr *)fetch(woody->file, woody->file_size, 0, sizeof(Elf64_Ehdr));
|
||||
if (!elf->Ehdr)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
elf->Phdr = (Elf64_Phdr *)fetch(woody->file, woody->file_size, elf->Ehdr->e_phoff, sizeof(Elf64_Phdr));
|
||||
if (!elf->Phdr)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
elf->Shdr = (Elf64_Shdr *)fetch(woody->file, woody->file_size, elf->Ehdr->e_shoff, sizeof(Elf64_Shdr));
|
||||
if (!elf->Shdr || !fetch(woody->file, woody->file_size, elf->Ehdr->e_shoff, elf->Ehdr->e_shnum * sizeof(Elf64_Shdr)))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (!fetch(woody->file, woody->file_size, elf->Ehdr->e_shoff + (elf->Ehdr->e_shstrndx * sizeof(Elf64_Shdr)), sizeof(Elf64_Shdr)))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
char *Sshstrtab = (char *)fetch(woody->file, woody->file_size, elf->Shdr[elf->Ehdr->e_shstrndx].sh_offset, 0);
|
||||
if (Sshstrtab == NULL)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
for (int i = 0; i < elf->Ehdr->e_shnum;i++)
|
||||
{
|
||||
if (elf->Shdr[i].sh_type == SHT_PROGBITS && elf->Shdr[i].sh_flags & SHF_EXECINSTR && elf->Shdr[i].sh_flags & SHF_ALLOC && elf->Shdr[i].sh_flags & SHF_EXECINSTR)
|
||||
{
|
||||
if (Sshstrtab + elf->Shdr[i].sh_name < (char *)woody->file + woody->file_size && !ft_strncmp(".text\0", Sshstrtab + elf->Shdr[i].sh_name, 6))
|
||||
{
|
||||
elf->text_section = &elf->Shdr[i];
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
Loading…
Reference in New Issue