picoCTF2018 Writeup之General skills篇
先知 2018-10-17
前言
接上篇,General-skills部分主要是一些linux命令的使用和小tricks。部分题目文件已打包为附件。
General Warmup 1 2 3
Question
If I told you your grade was 0x41 in hexadecimal, what would it be in ASCII?
Can you convert the number 27 (base 10) to binary (base 2)?
What is 0x3D (base 16) in decimal (base 10).
Solution
三题签到题,差不多一个意思,就放一起了。
>>> chr(0x41)
'A'
>>> bin(27)[2:]
'11011'
>>> 0x3d
61
flag:
picoCTF{A}
picoCTF{11011}
picoCTF{61}
Resources
Question
We put together a bunch of resources to help you out on our website! If you go over there, you might even find a flag! https://picoctf.com/resources (link)
Hint
No hints available
Solution
打开网页下拉,就能看到flag
Thanks for reading the resources page! Here’s a flag for your time: picoCTF{xiexie_ni_lai_zheli}
flag:picoCTF{xiexie_ni_lai_zheli}
Grep 1
Question
Can you find the flag in file? This would be really obnoxious to look through by hand, see if you can find a faster way. You can also find the file in /problems/grep-1_3_8d9cff3d178c231ab735dfef3267a1c2 on the shell server.
Hint
grep tutorial
Solution
grep
,(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。
cat file
会有一大堆乱码字符,使用grep picoCTF file
可以把flag从乱码中提取出来。
finn@pico-2018-shell-2:/problems/grep-1_2_ee2b29d2f2b29c65db957609a3543418$ grep picoCTF file
picoCTF{grep_and_you_will_find_42783683}
net cat
Question
Using netcat (nc) will be a necessity throughout your adventure. Can you connect to
2018shell1.picoctf.com
at port49387
to get the flag?
Hint
nc tutorial
Solution
nc
是一个简单、可靠的网络工具,可通过TCP或UDP协议传输读写数据。
通过nc连接题目的服务器得到flag。
❯ nc 2018shell2.picoctf.com 36356
That wasn't so hard was it?
picoCTF{NEtcat_iS_a_NEcESSiTy_9454f3e0}
flag:picoCTF{NEtcat_iS_a_NEcESSiTy_9454f3e0}
pipe
Question
During your adventure, you will likely encounter a situation where you need to process data that you receive over the network rather than through a file. Can you find a way to save the output from this program and search for the flag? Connect with
2018shell1.picoctf.com 48696
.
Hint
Remember the flag format is picoCTF{XXXX}
Ever heard of a pipe? No not that kind of pipe... This kind
Solution
管道命令操作符是:|
,它能处理经由前面一个指令传出的正确输出信息,也就是 standard output 的信息,然后作为标准的输入 standard input,传递给下一个命令。
连接服务器,配合grep
得到flag。
❯ nc 2018shell2.picoctf.com 34532 |grep picoCTF
picoCTF{almost_like_mario_b797f2b3}
flag:picoCTF{almost_like_mario_b797f2b3}
Strings
Question
Can you find the flag in this file without actually running it? You can also find the file in /problems/strings_2_b7404a3aee308619cb2ba79677989960 on the shell server.
Hint
Solution
strings
命令可以打印文件中可打印的字符,使用strings
命令配合grep
命令可以把flag提取出来。
finn@pico-2018-shell-2:/problems/strings_4_40d221755b4a0b134c2a7a2e825ef95f$ strings strings |grep picoCTF
picoCTF{sTrIngS_sAVeS_Time_d3ffa29c}
flag:picoCTF{sTrIngS_sAVeS_Time_d3ffa29c}
grep 2
Question
This one is a little bit harder. Can you find the flag in /problems/grep-2_3_826f886f547acb8a9c3fccb030e8168d/files on the shell server? Remember, grep is your friend.
Hint
grep tutorial
Solution
目录下有许多个文件夹,每个文件夹下面又有文件夹和文件。可以使用grep -r
选项来递归的搜寻文件。
finn@pico-2018-shell-2:/problems/grep-2_3_826f886f547acb8a9c3fccb030e8168d/files$ grep -r picoCTF
files2/file20:picoCTF{grep_r_and_you_will_find_556620f7}
flag:picoCTF{grep_r_and_you_will_find_556620f7}
Aca-Shell-A
Question
It's never a bad idea to brush up on those linux skills or even learn some new ones before you set off on this adventure! Connect with
nc 2018shell1.picoctf.com 27833
.
Hint
Linux for Beginners
Solution
这题用到了以下的基础linux命令:
ls
cd
rm
whoami
cat
- 如何执行二进制可执行文件
依照指示输入命令就可以了。
$ nc 2018shell1.picoctf.com 27833
Sweet! We have gotten access into the system but we aren't root.
It's some sort of restricted shell! I can't see what you are typing
but I can see your output. I'll be here to help you along.
If you need help, type "echo 'Help Me!'" and I'll see what I can do
There is not much time left!
~/$ ls
blackmail
executables
passwords
photos
secret
~/$ cd secret
Now we are cookin'! Take a look around there and tell me what you find!
~/secret$ ls
intel_1
intel_2
intel_3
intel_4
intel_5
profile_AipieG5Ua9aewei5ieSoh7aph
profile_Xei2uu5suwangohceedaifohs
profile_ahShaighaxahMooshuP1johgo
profile_ahqueith5aekongieP4ahzugi
profile_aik4hah9ilie9foru0Phoaph0
profile_bah9Ech9oa4xaicohphahfaiG
profile_ie7sheiP7su2At2ahw6iRikoe
profile_of0Nee4laith8odaeLachoonu
profile_poh9eij4Choophaweiwev6eev
profile_poo3ipohGohThi9Cohverai7e
Sabatoge them! Get rid of all their intel files!
~/secret$ rm intel*
Nice! Once they are all gone, I think I can drop you a file of an exploit!
Just type "echo 'Drop it in!' " and we can give it a whirl!
~/secret$ echo 'Drop it in!'
Drop it in!
I placed a file in the executables folder as it looks like the only place we can execute from!
Run the script I wrote to have a little more impact on the system!
~/secret$ cd ..
~/$ cd executables
~/executables$ ls
dontLookHere
~/executables$ ./dontLookHere
...
...
...
Looking through the text above, I think I have found the password. I am just having trouble with a username.
Oh drats! They are onto us! We could get kicked out soon!
Quick! Print the username to the screen so we can close are backdoor and log into the account directly!
You have to find another way other than echo!
~/executables$ whoami
l33th4x0r
Perfect! One second!
Okay, I think I have got what we are looking for. I just need to to copy the file to a place we can read.
Try copying the file called TopSecret in tmp directory into the passwords folder.
~/executables$ cp /tmp/TopSecret passwords
Server shutdown in 10 seconds...
Quick! go read the file before we lose our connection!
~/executables$ cd ..
~/$ ls
blackmail
executables
passwords
photos
secret
~/$ cd passwords
~/passwords$ ls
TopSecret
~/passwords$ cat TopSecret
Major General John M. Schofield's graduation address to the graduating class of 1879 at West Point is as follows: The discipline which makes the soldiers of a free country reliable in battle is not to be gained by harsh or tyrannical treatment.On the contrary, such treatment is far more likely to destroy than to make an army.It is possible to impart instruction and give commands in such a manner and such a tone of voice as to inspire in the soldier no feeling butan intense desire to obey, while the opposite manner and tone of voice cannot fail to excite strong resentment and a desire to disobey.The one mode or other of dealing with subordinates springs from a corresponding spirit in the breast of the commander.He who feels the respect which is due to others, cannot fail to inspire in them respect for himself, while he who feels,and hence manifests disrespect towards others, especially his subordinates, cannot fail to inspire hatred against himself.
picoCTF{CrUsHeD_It_9edaa84a}
flag:picoCTF{CrUsHeD_It_9edaa84a}
environ
Question
Sometimes you have to configure environment variables before executing a program. Can you find the flag we've hidden in an environment variable on the shell server?
Hint
unix env
Solution
考察linux系统环境变量,使用env
命令可以列出系统中所有的环境变量,配合grep
命令得到flag。
finn@pico-2018-shell-2:/problems/grep-2_3_826f886f547acb8a9c3fccb030e8168d/files$ env|grep pico
SECRET_FLAG=picoCTF{eNv1r0nM3nT_v4r14Bl3_fL4g_3758492}
flag:picoCTF{eNv1r0nM3nT_v4r14Bl3_fL4g_3758492}
ssh-keyz
Question
As nice as it is to use our webshell, sometimes its helpful to connect directly to our machine. To do so, please add your own public key to ~/.ssh/authorized_keys, using the webshell. The flag is in the ssh banner which will be displayed when you login remotely with ssh to with your username.
Hint
key generation tutorial
We also have an expert demonstrator to help you along. link
Solution
公钥连接服务器相关,在shell服务器中使用ssh-keygen -t rsa
生成自己的公私钥对,默认生成为~/.ssh/id_rsa.pub(公钥)和~/.ssh/id_rsa(私钥),将私钥下载到本地,然后用ssh <username>@2018shell2.picoctf.com
连接服务器即可在欢迎信息的banner中看到flag。
这题也可以直接查看banner文件。
finn@pico-2018-shell-2:~$ cat /etc/ssh/sshd_config |grep banner
Banner /opt/ssh_banner
finn@pico-2018-shell-2:~$ cat /opt/ssh_banner
picoCTF{who_n33ds_p4ssw0rds_38dj21}
flag:picoCTF{who_n33ds_p4ssw0rds_38dj21}
what base is this?
Question
To be successful on your mission, you must be able read data represented in different ways, such as hexadecimal or binary. Can you get the flag from this program to prove you are ready? Connect with
nc 2018shell1.picoctf.com 1225
.
Hint
I hear python is a good means (among many) to convert things.
It might help to have multiple windows open
Solution
三个不通的进制转换,分别是二进制、十六进制和八进制,转换为十进制,然后发送对应ascii码的单词,写个脚本处理一下就可以了。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pwn import *
import re
r = remote('2018shell2.picoctf.com', 31711)
binary = r.recvuntil('as a word.')
binary = re.findall(r'(d+)', binary)
binary_word = ''.join([chr(int(i, 2)) for i in binary])
r.sendline(binary_word)
hexnum = r.recvuntil('as a word.')
hexnum = re.findall(r'([0-9a-f]+) as', hexnum)[0]
hexword = hexnum.decode('hex')
r.sendline(hexword)
octal = r.recvuntil('as a word.')
octal = re.findall(r'([0-9]+)', octal)
octal_word = ''.join([chr(int(i, 8)) for i in octal])
r.sendline(octal_word)
print r.recvuntil('}n')
r.close()
$ python nc_convert.py
[+] Opening connection to 2018shell2.picoctf.com on port 31711: Done
Input:
You got it! You're super quick!
Flag: picoCTF{delusions_about_finding_values_68051dea}
[*] Closed connection to 2018shell2.picoctf.com port 31711
flag:picoCTF{delusions_about_finding_values_68051dea}
you can't see me
Question
'...reading transmission... Y.O.U. .C.A.N.'.T. .S.E.E. .M.E. ...transmission ended...' Maybe something lies in /problems/you-can-t-see-me_3_1a39ec6c80b3f3a18610074f68acfe69.
Hint
What command can see/read files?
What's in the manual page of ls?
Solution
ls -a
可以查看以.
开头的隐藏文件。
finn@pico-2018-shell-2:/problems/you-can-t-see-me_2_cfb71908d8368e3062423b45959784aa$ ls -a
. . ..
其中一个.
代表当前目录,另一个是一个文件,直接cat .
会显示
finn@pico-2018-shell-2:/problems/you-can-t-see-me_2_cfb71908d8368e3062423b45959784aa$ cat .
cat: .: Is a directory
输入cat
然后用tab键补全就能看到真正的文件名了,是一个.
和两个空格
finn@pico-2018-shell-2:/problems/you-can-t-see-me_2_cfb71908d8368e3062423b45959784aa$ cat .
picoCTF{j0hn_c3na_paparapaaaaaaa_paparapaaaaaa_093d6aff}
flag:picoCTF{j0hn_c3na_paparapaaaaaaa_paparapaaaaaa_093d6aff}
absolutely relative
Question
In a filesystem, everything is relative ¯_(ツ)_/¯. Can you find a way to get a flag from this program? You can find it in /problems/absolutely-relative_1_15eb86fcf5d05ec169cc417d24e02c87 on the shell server. Source.
Hint
Do you have to run the program in the same directory? (⊙.☉)7
Ever used a text editor? Check out the program 'nano'
Solution
阅读程序源码
#include <stdio.h>
#include <string.h>
#define yes_len 3
const char *yes = "yes";
int main()
{
char flag[99];
char permission[10];
int i;
FILE * file;
file = fopen("/problems/absolutely-relative_0_d4f0f1c47f503378c4bb81981a80a9b6/flag.txt" , "r");
if (file) {
while (fscanf(file, "%s", flag)!=EOF)
fclose(file);
}
file = fopen( "./permission.txt" , "r");
if (file) {
for (i = 0; i < 5; i++){
fscanf(file, "%s", permission);
}
permission[5] = '