Computer Security

#17 Wargame bandit 14 (Level28 ~ Level30), branch,git log,git show,git checkout 명령어 본문

Wargame:Bandit

#17 Wargame bandit 14 (Level28 ~ Level30), branch,git log,git show,git checkout 명령어

쿠리 Kuri 2022. 7. 24. 18:30

Level28 -> Level29

bandit28

ssh://bandit28-git@localhost/home/bandit28-git/repo에 git 저장소가 있습니다. 
bandit28-git 사용자의 비밀번호는 bandit28 사용자의 비밀번호와 동일합니다.
저장소를 복제하고 다음 레벨의 비밀번호를 찾으십시오.

git log

  • git log는 현재 브랜치의 커밋 이력을 볼 수 있는 명령어다.
$ git log
# 현재 브랜치의 커밋 이력을 보는 명령어
# HEAD와 관련된 커밋들이 자세하게 나온다

$ git log -n<숫자>
# 전체 커밋 중에서 최신 n개의 커밋을 살펴본다

$ git log --oneline --graph --decorate --all
# 모든 브랜치들을 보고 싶을 때

# --oneline : 현재 커밋을 한 줄로 요약해서 보여준다
# --graph : 커밋 옆에 브랜치의 흐름을 그래프로 보여준다
# --decorate : 원래는 --decorate=short 옵션을 의미한다. 브랜치와 태그 등의 참조를 간결히 표시한다
# --all : all 옵션이 없을 경우 HEAD와 관계 없는 옵션은 보여주지 않는다

$ git log --patch
$ git log --p
# 파일의 수정된 내용도 함께 확인할 수 있다

$ git log --oneline
# 간단히 커멧 해시와 제목만 보고 싶을 때

$ git log --oneline --reverse
# 오래된 커밋부터 보고 싶을 때

$ git log --oneline --graph --decorate
# HEAD와 관련된 커밋들을 조금 더 자세히 보고 싶을 때

$ git log --oneline --graph --all --decorate
# 모든 브랜치들을 보고싶을 때

$ git log --oneline -n5
# 내 브랜치의 최신 커밋을 5개만 보고 싶을 때

$ git log --pretty=oneline
# --pretty 옵션 사용하면 원하는 대로 git log를 foramtting할 수 있다
# --pretty=oneline처럼 oneline을 이용하면 전체 해쉬코드가 출력된다

$ git log --pretty=format:"%h %an"
# 사용자가 원하는 방식으로 format을 만들 수 있다
# 해쉬코드와 author의 이름만 보고 싶은 경우 %h %an를 사용한다

$ git log --pretty=format:"%h %an %ar %s "
# 해쉬코드, author의 이름과 commit 된 date와 title까지 보고 싶은 경우


# https://git-scm.com/docs/git-log
# 다양한 옵션 확인가능

$ git log --graph --all --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(white)%s %C(bold red)%C(reset) %C(blue)%d%C(reset)' --date=short
# 이렇게 format을 지정하면 사용자가 좀 더 편하게 log 결과를 볼 수 있다
# 다만 이렇게 설정하면 너무 길기 때문에 아래처럼 alias를 사용해서 명령어를 줄인다

$ git config --global alias.hist "log --graph --all --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(white)%s %C(bold red)%C(reset) %C(blue)%d%C(reset)' --date=short"
# 이렇게 hist 라는 이름으로 지정해주면 (꼭 hist라는 이름으로 지정하지 않아도 된다)

$ git hist
# 로 해도 같은 결과를 출력할 수 있다

$ git log -3
# 최근 커밋 중 3개만 볼 수 있다

$ git log --oneline -3
# 최근 커밋 중 3개만 간단하게 볼 수 있다

$ git log --author-"john"
# 커밋 작성자가 john인 사람의 커밋만 보여준다

$ git log --before="2020-09-09"
# 지정한 날짜 이전 커밋만 보여준다

$ git log --grep="page"
# 커밋 중에 page라는 단어가 포함된 커밋만 보여준다


$ git log -S "about"
# 커밋 타이틀이 아니라 소스코드 컨텐츠 안에서 문자를 검색하고 싶다면
# 소스코드 내용 중에 about이라는 글자가 포함된 소스코드에 대한 커밋 보여준다


$ git log -S "about" -p
$ git log -S "about" --patch
# 조금 더 자세히 알고 싶다면 -p명령어를 사용해서 보면
# 코드 내용안에 about이라는 글자가 포함된 소스코드에 대한 커밋과 "about"이 포함된 내용을 함께 보여준다


$ git log about.txt
# git log 다음에 파일 이름 작성하면 해당하는 파일에 대한 커밋을 볼 수 있다
# about.txt라는 파일에 대한 커밋을 몰 수 있다

$ git log -p about.txt
# -p 옵션을 사용하면 수정된 파일의 내용까지 함께 확인할 수 있다

$ git log -s about.txt
# -s 옵션을 써서 간단한 상태만 확인할 수 있다

$ git log HEAD
# HEAD는 내가 보고 있는 커밋을 가르킨다
# git log 와 동일한 내용을 보여준다

$ git log HEAD~1
# HEAD에서 첫번째 떨어진 부모부터 보여준다

$ git log HEAD~2
# HEAD에서 두번째 떨어진 부모부터 보여준다

$ git show "commit_hashcode"
# 특정 commit에 대한 내용을 확인하고 싶은 경우 show 옵션 사용한다

$ git show "commit_hashcode":"file name"
# commit에 여러개의 파일이 있을 때 다음과 같은 방법으로 file의 내용을 확인할 수 있다

$ git diff "commit_hashcode" "commit_hashcode"
# 두 커밋을 비교해서 어떠한 부분이 변경되었는지 확인할 수 있다

$ git diff "commit_hashcode" "commit_hashcode" "filename"
# 두 커밋에서 해당하는 파일의 차이점을 확인할 수 있다


$ git help <명령어>
# 해당 명령어의 도움말을 표시한다

# 도움말 기능 사용하기
# git help <명령어> , 해당 명령어의 도움말을 표시한다
$ git help status

$ git help commit

특정 commit 확인 : git show [commit id]

git show <commit id>는 commit id의 정보 및 수정 내용을 보여준다.


 

1.이전문제와 비슷한 문제인 것 같다.  cd 명령어로 tmp 디렉토리에 접근한 뒤, mkdir 을 이용해 banduit28이라는 디렉토리를 하나 만들어 bandit28에 접근하자.

bandit28@bandit:~$ ls -al
total 20
drwxr-xr-x  2 root root 4096 May  7  2020 .
drwxr-xr-x 41 root root 4096 May  7  2020 ..
-rw-r--r--  1 root root  220 May 15  2017 .bash_logout
-rw-r--r--  1 root root 3526 May 15  2017 .bashrc
-rw-r--r--  1 root root  675 May 15  2017 .profile
bandit28@bandit:~$ ls
bandit28@bandit:~$ ls -a
.  ..  .bash_logout  .bashrc  .profile
bandit28@bandit:~$ cd /tmp
bandit28@bandit:/tmp$ mkdir ./bandit28
bandit28@bandit:/tmp$ cd ./bandit28
bandit28@bandit:/tmp/bandit28$ ls -al
total 1992
drwxr-sr-x 2 bandit28 root    4096 Jul 20 14:52 .
drwxrws-wt 1 root     root 2031616 Jul 20 14:53 ..

 

 

 

2. 이제 이 bandit28안에 git clone명령어를 이용해 복제를 한다.

bandit28@bandit:/tmp/bandit28$ git clone ssh://bandit28-git@localhost/home/bandit28-git/repo
Cloning into 'repo'...
Could not create directory '/home/bandit28/.ssh'.
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/bandit28/.ssh/known_hosts).
This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

bandit28-git@localhost's password:
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 9 (delta 2), reused 0 (delta 0)
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (2/2), done.

 

 

 

3.ls 명령어로 확인 해보니 README.md가 존재한다. 읽어 보자.

bandit28@bandit:/tmp/bandit28$ ls -al
total 1996
drwxr-sr-x 3 bandit28 root    4096 Jul 20 14:53 .
drwxrws-wt 1 root     root 2031616 Jul 20 14:53 ..
drwxr-sr-x 3 bandit28 root    4096 Jul 20 14:53 repo
bandit28@bandit:/tmp/bandit28$ cd repo
bandit28@bandit:/tmp/bandit28/repo$ ls
README.md
bandit28@bandit:/tmp/bandit28/repo$ cat README.md
# Bandit Notes
Some notes for level29 of bandit.

## credentials

- username: bandit29
- password: xxxxxxxxxx

 

 

 

4.비밀번호가 xxxxxxx로 설정이 되어있어서 지금 현재로써는 보지 못한다... 이때 , 이사람이 혹시 비밀번호를 썼다가 지우고 xxxx로바꾼 것일 수  있으니 git log명령어를 이용해 commit(임시저장)을 본다.

bandit28@bandit:/tmp/bandit28/repo$ git log
commit edd935d60906b33f0619605abd1689808ccdd5ee
Author: Morla Porla <morla@overthewire.org>
Date:   Thu May 7 20:14:49 2020 +0200

    fix info leak

commit c086d11a00c0648d095d04c089786efef5e01264
Author: Morla Porla <morla@overthewire.org>
Date:   Thu May 7 20:14:49 2020 +0200

    add missing data

commit de2ebe2d5fd1598cd547f4d56247e053be3fdc38
Author: Ben Dover <noone@overthewire.org>
Date:   Thu May 7 20:14:49 2020 +0200

    initial commit of README.md

 

 

 

5. 제일 위에 edd935d60906b33f0619605abd1689808ccdd5ee 이것이 가장 최신이다. fix info leak라 되어있는데, 무엇을 고친건지 git show 명령어로 확인 해보겠다.

bandit28@bandit:/tmp/bandit28/repo$ git show edd935d60906b33f0619605abd1689808ccdd5ee
commit edd935d60906b33f0619605abd1689808ccdd5ee
Author: Morla Porla <morla@overthewire.org>
Date:   Thu May 7 20:14:49 2020 +0200

    fix info leak

diff --git a/README.md b/README.md
index 3f7cee8..5c6457b 100644
--- a/README.md
+++ b/README.md
@@ -4,5 +4,5 @@ Some notes for level29 of bandit.
 ## credentials

 - username: bandit29
-- password: bbc96594b4e001778eee9975372716b2
+- password: xxxxxxxxxx

bbc96594b4e001778eee9975372716b2 을 없애고 xxx를 추가 시킨것으로 보아 bandit29 비밀번호는 bbc96594b4e001778eee9975372716b2 인것 같다.

 

 

 

6. 위에서 얻은 비밀번호로 bandit29에 접속하면 성공!.

 For your convenience we have installed a few usefull tools which you can find
 in the following locations:

    * gef (https://github.com/hugsy/gef) in /usr/local/gef/
    * pwndbg (https://github.com/pwndbg/pwndbg) in /usr/local/pwndbg/
    * peda (https://github.com/longld/peda.git) in /usr/local/peda/
    * gdbinit (https://github.com/gdbinit/Gdbinit) in /usr/local/gdbinit/
    * pwntools (https://github.com/Gallopsled/pwntools)
    * radare2 (http://www.radare.org/)
    * checksec.sh (http://www.trapkit.de/tools/checksec.html) in /usr/local/bin/checksec.sh

--[ More information ]--

  For more information regarding individual wargames, visit
  http://www.overthewire.org/wargames/

  For support, questions or comments, contact us through IRC on
  irc.overthewire.org #wargames.

  Enjoy your stay!

bandit29@bandit:~$

Level29 -> Level30

Level29


branch란?

  • 독립적으로 어떤 작업을 진행하기 위한 개념이다.
  • 필요에 의해 만들어지는 각각의 브랜치는 다른 브랜치의 영향을 받지 않기 때문에, 여러 작업을 동시에 진행할 수 있다.
  • 또한 이렇게 만들어진 브랜치는 다른 브랜치와 병합(Merge)함으로써, 작업한 내용을 다시 새로운 하나의 브랜치로 모을 수 있다.
  • 여러 명이서 동시에 작업을 할 때에 다른 사람의 작업에 영향을 주거나 받지 않도록, 먼저 메인 브랜치에서 자신의 작업 전용 브랜치를 만든다.
  • 그리고 각자 작업을 진행한 후, 작업이 끝난 사람은 메인 브랜치에 자신의 브랜치의 변경 사항을 적용한다.
  • 이렇게 함으로써 다른 사람의 작업에 영향을 받지 않고 독립적으로 특정 작업을 수행하고 그 결과를 하나로 모아 나가게 된다.
  • 이러한 방식으로 작업할 경우 '작업 단위', 즉 브랜치로 그 작업의 기록을 중간 중간에 남기게 되므로 문제가 발생했을 경우 원인이 되는 작업을 찾아내거나 그에 따른 대책을 세우기 쉬워진다.

 

master branch

  • 저장소를 처음 만들면, Git은 바로 'master'라는 이름의 브랜치를 만들어 둔다.
  • 이 새로운 저장소에 새로운 파일을 추가 한다거나 추가한 파일의 내용을 변경하여 그 내용을 저장(커밋, Commit)하는 것은 모두 'master' 라는 이름의 브랜치를 통해 처리할 수 있는 일이 된다.
  • 'master'가 아닌 또 다른 새로운 브랜치를 만들어서 '이제부터 이 브랜치를 사용할거야!'라고 선언(체크아웃, checkout)하지 않는 이상, 이 때의 모든 작업은 'master' 브랜치에서 이루어 진다.

 

git checkout (브랜치)

  • 현재 master 브랜치에서 다른 브랜치로 이동하려면 checkout 명령어를 사용한다.
  • git chechout (다른 브랜치)

 

git checkout -b (새로운 브랜치)

  • 브랜치 생성과 체크아웃을 한번에 하려면 git checkout -b (branch이름)을 입력한다.
  • 새로운 브랜치가 생성되고 생성된 새로운 브랜치로 체크아웃된다.

 

git branch [-l]

  • 로컬 branch 정보를 보여준다. (-l 옵션은 생략가능)
 

git branch -v

  • 로컬 branch의 정보를 마지막 커밋 내역과 함께 보여준다.
 

git branch -r

  • 리모트 저장소의 branch 정보를 보여준다.
 

git branch -a

  • 로컬/리모트 저장소의 모든 branch 정보를 보여준다.
 

git branch (이름)

  • 로컬에 새로운 branch를 생성한다.
  • 생성과 동시에 해당 branch로 이동하려면 아래 명령어를 사용한다.
  • 원격에 있는 branch를 가져오려면 아래 명령어를 사용한다.
 

git branch (–merged | –no-merged)

  • --merged는 이미 merge된 branch를 표시해주고 --no-merged는 아직 merge가 되지 않은 branch만 표시한다.
  • --merged에 branch 목록 이미 merge되었기 때문에 *가 표시되지 않은 branch는 삭제 가능하다.
 
 

git branch -d (branch 이름)

  • branch를 삭제한다.
  • 아직 merge하지 않은 커밋을 담고 있는 경우 삭제되지 않는다.(강제종료 옵션 -D으로만 삭제 가능)
 

git branch -m (변경할 branch이름) (변경될 branch이름)

  • A 브랜치를 B 브랜치로 변경한다.
  • -M 옵션을 사용할 경우 기존에 동일한 이름의 branch가 있더라도 덮어쓴다.

1.이전문제와 비슷한 문제인 것 같다.  cd 명령어로 tmp 디렉토리에 접근한 뒤, mkdir 을 이용해 banduit29이라는 디렉토리를 하나 만들어 bandit29에 접근하자.

bandit29@bandit:~$ ls -al
total 20
drwxr-xr-x  2 root root 4096 May  7  2020 .
drwxr-xr-x 41 root root 4096 May  7  2020 ..
-rw-r--r--  1 root root  220 May 15  2017 .bash_logout
-rw-r--r--  1 root root 3526 May 15  2017 .bashrc
-rw-r--r--  1 root root  675 May 15  2017 .profile
bandit29@bandit:~$ cd /tmp
bandit29@bandit:/tmp$ mkdir ./bandit29
bandit29@bandit:/tmp$ cd ./bandit29

 

 

 

2. 이제 이 bandit29안에 git clone명령어를 이용해 복제를 한다.

bandit29@bandit:/tmp/bandit29$ git clone ssh://bandit29-git@localhost/home/bandit29-git/repo
Cloning into 'repo'...
Could not create directory '/home/bandit29/.ssh'.
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:98UL0ZWr85496EtCRkKlo20X3OPnyPSB5tB5RPbhczc.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/bandit29/.ssh/known_hosts).
This is a OverTheWire game server. More information on http://www.overthewire.org/wargames

bandit29-git@localhost's password:
remote: Counting objects: 16, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 16 (delta 2), reused 0 (delta 0)
Receiving objects: 100% (16/16), done.
Resolving deltas: 100% (2/2), done.

 

 

 

3. README.md 파일을 읽어보니 no pass words~ 라 한다. git log로 읽어보자.

bandit29@bandit:/tmp/bandit29$ ls -al
total 1996
drwxr-sr-x 3 bandit29 root    4096 Jul 20 15:16 .
drwxrws-wt 1 root     root 2031616 Jul 20 15:16 ..
drwxr-sr-x 3 bandit29 root    4096 Jul 20 15:16 repo
bandit29@bandit:/tmp/bandit29$ cd repo
bandit29@bandit:/tmp/bandit29/repo$ ls
README.md
bandit29@bandit:/tmp/bandit29/repo$ cat README.md
# Bandit Notes
Some notes for bandit30 of bandit.

## credentials

- username: bandit30
- password: <no passwords in production!>
bandit29@bandit:/tmp/bandit29/repo$ git log
commit 208f463b5b3992906eabf23c562eda3277fea912
Author: Ben Dover <noone@overthewire.org>
Date:   Thu May 7 20:14:51 2020 +0200

    fix username

commit 18a6fd6d5ef7f0874bbdda2fa0d77b3b81fd63f7
Author: Ben Dover <noone@overthewire.org>
Date:   Thu May 7 20:14:51 2020 +0200

    initial commit of README.md

 

 

 

4. git log로는 이번엔 특이한 점을 찾지 못했다. git branch  -a 를 이용해 branch를 확인한다. 

bandit29@bandit:/tmp/bandit29/repo$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/master
  remotes/origin/sploits-dev

기본적으론 master branch로 설정되어있다.

 

 

 

5. git checkout으로  branch를 /dev 로 바꿔서 log를 살펴보자.

bandit29@bandit:/tmp/bandit29/repo$ git checkout remotes/origin/dev
Note: checking out 'remotes/origin/dev'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at bc83328... add data needed for development

 

 

 

6.git branch -a 로 다시 보니, branch의 위치가 바뀐 것을 알 수 있다.

bandit29@bandit:/tmp/bandit29/repo$ git branch -a
* (HEAD detached at origin/dev)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/master
  remotes/origin/sploits-dev

 

 

 

7. git log로 로그 살피고, 젤 위에 commit을 git show로 살펴보자.

bandit29@bandit:/tmp/bandit29/repo$ git log
commit 33ce2e95d9c5d6fb0a40e5ee9a2926903646b4e3
Author: Morla Porla <morla@overthewire.org>
Date:   Tue Oct 16 14:00:41 2018 +0200

    add data needed for development

commit a8af722fccd4206fc3780bd3ede35b2c03886d9b
Author: Ben Dover <noone@overthewire.org>
Date:   Tue Oct 16 14:00:41 2018 +0200

    add gif2ascii

commit 84abedc104bbc0c65cb9eb74eb1d3057753e70f8
Author: Ben Dover <noone@overthewire.org>
Date:   Tue Oct 16 14:00:41 2018 +0200

    fix username

commit 9b19e7d8c1aadf4edcc5b15ba8107329ad6c5650
Author: Ben Dover <noone@overthewire.org>
Date:   Tue Oct 16 14:00:41 2018 +0200

    initial commit of README.md

 

 

 

8. bandit30의 패스워드: 5b90576bedb2cc04c86a9e924ce42faf  가 나온다!!

bandit29@bandit:/tmp/bandit29/repo$ git show bc833286fca18a3948aec989f7025e23ffc16c07
commit bc833286fca18a3948aec989f7025e23ffc16c07
Author: Morla Porla <morla@overthewire.org>
Date:   Thu May 7 20:14:52 2020 +0200

    add data needed for development

diff --git a/README.md b/README.md
index 1af21d3..39b87a8 100644
--- a/README.md
+++ b/README.md
@@ -4,5 +4,5 @@ Some notes for bandit30 of bandit.
 ## credentials

 - username: bandit30
-- password: <no passwords in production!>
+- password: 5b90576bedb2cc04c86a9e924ce42faf

 

 

 

9.얻은 bandit30의 비밀번호:5b90576bedb2cc04c86a9e924ce42faf  로 bandit30에 접속하면 성공! 

 For your convenience we have installed a few usefull tools which you can find
 in the following locations:

    * gef (https://github.com/hugsy/gef) in /usr/local/gef/
    * pwndbg (https://github.com/pwndbg/pwndbg) in /usr/local/pwndbg/
    * peda (https://github.com/longld/peda.git) in /usr/local/peda/
    * gdbinit (https://github.com/gdbinit/Gdbinit) in /usr/local/gdbinit/
    * pwntools (https://github.com/Gallopsled/pwntools)
    * radare2 (http://www.radare.org/)
    * checksec.sh (http://www.trapkit.de/tools/checksec.html) in /usr/local/bin/checksec.sh

--[ More information ]--

  For more information regarding individual wargames, visit
  http://www.overthewire.org/wargames/

  For support, questions or comments, contact us through IRC on
  irc.overthewire.org #wargames.

  Enjoy your stay!

bandit30@bandit:~$
Comments