<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>path_finder.log</title>
        <link>https://velog.io/</link>
        <description>한 줄로 소개하기엔 여백이 좁아 적지 않겠습니다.</description>
        <lastBuildDate>Tue, 25 Apr 2023 17:18:23 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>path_finder.log</title>
            <url>https://velog.velcdn.com/images/path_finder/profile/1f640980-816e-4fca-96a8-a6904bababee/image.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. path_finder.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/path_finder" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[git/github] 버전을 만들어보자]]></title>
            <link>https://velog.io/@path_finder/gitgithub-%EB%B2%84%EC%A0%84%EC%9D%84-%EB%A7%8C%EB%93%A4%EC%96%B4%EB%B3%B4%EC%9E%90</link>
            <guid>https://velog.io/@path_finder/gitgithub-%EB%B2%84%EC%A0%84%EC%9D%84-%EB%A7%8C%EB%93%A4%EC%96%B4%EB%B3%B4%EC%9E%90</guid>
            <pubDate>Tue, 25 Apr 2023 17:18:23 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/path_finder/post/1f382df0-bfc1-4cd0-88ba-c50acdbd8ac1/image.gif" alt=""></p>
<p>📌 흐름을 이해하기</p>
<h3 id="이제부터-이-폴더-안에서-버전관리를-시작할거야">이제부터 이 폴더 안에서 버전관리를 시작할거야!</h3>
<pre><code class="language-bash">$ git init</code></pre>
<h3 id="이-폴더의-상태를-확인하고-싶다">이 폴더의 상태를 확인하고 싶다!</h3>
<pre><code class="language-bash">$ git status
On branch master

No commits yet

Untracked files:
  (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)
        test.txt

nothing added to commit but untracked files present (use &quot;git add&quot; to track)</code></pre>
<p><code>No commit yet</code> 아직 커밋되지 않았다</p>
<p><code>Untracked files</code> 못보던 새로운 파일이 생겼습니다!</p>
<h3 id="이제-testtxt를--staging-area로-올려보자">이제 test.txt를  staging area로 올려보자!</h3>
<pre><code class="language-bash">$ git add test.txt 
                                        // 아무것도 안뜨면 잘 add 된거임
$ git status
On branch master

No commits yet

Changes to be committed: // 변화가 감지됐다!
  (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)
        new file:   test.txt</code></pre>
<h3 id="다시-내리는-것도-가능">다시 내리는 것도 가능?</h3>
<pre><code class="language-bash">$ git rm --cached test.txt
rm &#39;test.txt&#39;

$ git status
On branch master

No commits yet

Untracked files:
  (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)
        test.txt</code></pre>
<h3 id="올려야할-파일이-너무-많거나-전부-올리려면-어떡해요">올려야할 파일이 너무 많거나 전부 올리려면 어떡해요?</h3>
<pre><code class="language-bash">$ git add .     // 모두  staging area 로 옮겨라! 는 의미</code></pre>
<h3 id="staging-area에서-depository로-옮기기">Staging Area에서 Depository로 옮기기</h3>
<pre><code class="language-bash">$ git commit -m &quot;commit message&quot;</code></pre>
<pre><code class="language-bash">$ git commit -m &quot;first commit&quot;
[master (root-commit) 0c580a9] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt</code></pre>
<p><strong>커밋 메세지가 뭔가요?</strong> </p>
<p>📌 어떤 변경사항이 생겨서 버전을 생성했는지 알려주기 위해 적는 메시지</p>
<h3 id="커밋한-내역을-확인하고-싶어요">커밋한 내역을 확인하고 싶어요</h3>
<pre><code class="language-bash">$ git log
commit 0c580a93a7919d0c6ec3ab99a01153ac534d5537 (HEAD -&gt; master)
Author: Eugene Kim &lt;hash_ff0000@naver.com&gt;
Date:   Wed Apr 26 01:39:24 2023 +0900

    first commit</code></pre>
<h3 id="만약-파일을-수정한다면">만약 파일을 수정한다면?</h3>
<pre><code class="language-bash">$ git status
On branch master
Changes not staged for commit:
  (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
  (use &quot;git restore &lt;file&gt;...&quot; to discard changes in working directory)
        modified:   test.txt

no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)</code></pre>
<h3 id="수정한-파일을-다시-staging-area로-옮기는건">수정한 파일을 다시 Staging Area로 옮기는건?</h3>
<pre><code class="language-bash">$ git add test.txt

$ git status
On branch master
Changes to be committed:
  (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)
        modified:   test.txt</code></pre>
<h3 id="그걸-버전으로-만들려면">그걸 버전으로 만들려면?</h3>
<pre><code class="language-bash">$ git commit -m &quot;add string to test&quot;
[master 7f63648] add string to test
 1 file changed, 1 insertion(+), 1 deletion(-)

$ git log
commit 7f63648c15ef69c06a302883b098f9b384883d26 (HEAD -&gt; master)
Author: Eugene Kim &lt;hash_ff0000@naver.com&gt;
Date:   Wed Apr 26 01:49:38 2023 +0900

    add string to test

commit 0c580a93a7919d0c6ec3ab99a01153ac534d5537
Author: Eugene Kim &lt;hash_ff0000@naver.com&gt;
Date:   Wed Apr 26 01:39:24 2023 +0900

    first commit</code></pre>
<h3 id="commit에-관하여">commit에 관하여</h3>
<p>commit할때 -m을 붙이지 않으면 자동으로 vi가 실행되는데, 그곳에 commit message를 더욱 자세히 적을 수 있다!</p>
<h3 id="여기서-드는-의문점">여기서 드는 의문점</h3>
<aside>
❓ `git commit` 명령어를 통해 버전을 만들면 내 컴퓨터 속 저장소에만 저장되는데 

<p>어떻게 다른 사람과 원격으로 협업을 할 수가 있는거죠?
효율적으로 백업했다고 말할 수 있나요?</p>
</aside>

<p><strong>⇒ 그래서 깃헙을 쓰는거다!</strong></p>
<p>: 각자의 컴퓨터에만 존재하는 버전을 저장, 관리해주는 서비스</p>
<p>github에 코드를 업로드 한다 == github에 <code>push</code>한다.</p>
<p>📌 내 컴퓨터 : Local 저장소 </p>
<p>github이 관리하는 컴퓨터 : 원격 저장소</p>
<p>Repository에 있는 모든 version이 모두 원격 저장소로 올라간다고 생각하면 됩니다</p>
<h4 id="출처">출처</h4>
<p><a href="https://www.inflearn.com/course/%EB%B9%A0%EB%A5%B4%EA%B2%8C-git/dashboard">https://www.inflearn.com/course/%EB%B9%A0%EB%A5%B4%EA%B2%8C-git/dashboard</a></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[git/github] 버전 관리의 큰그림]]></title>
            <link>https://velog.io/@path_finder/gitgithub</link>
            <guid>https://velog.io/@path_finder/gitgithub</guid>
            <pubDate>Tue, 25 Apr 2023 17:14:50 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/path_finder/post/4452cbd9-c84e-47f4-8939-6722fe2b04d3/image.gif" alt=""></p>
<h1 id="git이란">git이란?</h1>
<p>: 버전 관리 시스템</p>
<h3 id="버전">버전</h3>
<p>게임에서 나오는 버전</p>
<p>: 유의미한 변화가 결과물로 나온것</p>
<p>⇒ 하나의 버전을 관리하는 과정에서 협업이 필요하다.</p>
<p>⇒ 하나의 버전이 관리되는 과정에서 되돌리는 과정이 필요하다</p>
<p>⇒ 하나의 버전이 관리되는 과정에서 효율적인 백업이 필요하다.</p>
<p>이것들을 해주는 도구 : git</p>
<h3 id="버전이-만들어지는-두개의-단계">버전이 만들어지는 두개의 단계</h3>
<p><img src="https://velog.velcdn.com/images/path_finder/post/61777507-fcdf-422d-aab6-8e5a07b6a811/image.jpg" alt=""></p>
<p><strong>📌 버전이 되기까지 거쳐가는 두개의 단계, 세개의 공간이 있음</strong></p>
<ol>
<li><p>Working directory</p>
<p> : 작업 공간, </p>
<ul>
<li><p>내가 코드 작업을 하는 공간</p>
</li>
<li><p>파일들이 만들어지는 공간</p>
</li>
<li><p>즉, 변경사항이 생기는 공간</p>
<p>Q. 여기서 모든 변경사항을 버전으로 만들어야 하는가?</p>
<p>A. 변경 사항들 중 다음 버전이 될 파일들을 선별해서, 선별된 파일들을 버전으로 만들자!</p>
</li>
</ul>
</li>
<li><p>Staging Area</p>
<ul>
<li>버전이 될 후보들이 올라오는 공간</li>
<li>Working directory 에서 선별</li>
</ul>
</li>
<li><p>Repository</p>
<ul>
<li>진짜 버전이 저장되는 공간</li>
</ul>
</li>
</ol>
<h1 id="명령어-맛보기">명령어 맛보기</h1>
<pre><code class="language-bash">git &lt;명령어&gt;
git add // 변경된 파일을 Staging Area로 옮김
git commit // Staging Area의 파일을 Repository로 옮김</code></pre>
<h5 id="출처">출처</h5>
<p><a href="https://www.inflearn.com/course/%EB%B9%A0%EB%A5%B4%EA%B2%8C-git/dashboard">https://www.inflearn.com/course/%EB%B9%A0%EB%A5%B4%EA%B2%8C-git/dashboard</a></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Shellcode]]></title>
            <link>https://velog.io/@path_finder/Shellcode</link>
            <guid>https://velog.io/@path_finder/Shellcode</guid>
            <pubDate>Thu, 20 Apr 2023 12:13:43 GMT</pubDate>
            <description><![CDATA[<h1 id="소개">소개</h1>
<h2 id="익스플로잇-exploit">익스플로잇 (Exploit)</h2>
<p>상대 시스템을 공격하는 것</p>
<h2 id="셸-코드-shellcode">셸 코드 (Shellcode)</h2>
<ul>
<li>익스플로잇을 위해 제작된 어셈블리 코드 조각</li>
<li>일반적으로 셸을 획득하기 위한 목적으로 셸코드 사용</li>
<li>셸을 획득하는 것은 시스템 해킹에서 매우 중요</li>
</ul>
<p>⭐ 해커가 rip을 자신이 작성한 셸코드의 주소로 변경</p>
<ul>
<li>셸 코드는 어셈블리어로 구성된 만큼 아키텍처와 운영체제에 따라 다르게 작성해야함</li>
</ul>
<h2 id="orw-shellcode">orw Shellcode</h2>
<ul>
<li>파일을 엵고 읽은 뒤 화면에 출력해주는 셸코드</li>
<li>/tmp/flag 를 읽는 셸코드 작성</li>
</ul>
<pre><code class="language-c">char buf[0x30];

int fd = open(&quot;/tmp/flag&quot;, RD_ONLY, NULL);
read(fd, buf, 0x30);
write(1, buf, 0x30);</code></pre>
<h3 id="📌-알아두어야-하는-system-call">📌 알아두어야 하는 System Call</h3>
<p><img src="https://velog.velcdn.com/images/path_finder/post/a79a1242-bb6b-4711-8a22-7fe1b6de8375/image.png" alt=""></p>
<h3 id="구현">구현</h3>
<pre><code class="language-nasm">; int fd = open(&quot;/tmp/flag&quot;, O_RDONLY, NULL) 이 부분을 구현할거임

push 0x67 ; g의 아스키코드 g는 왜 따로 하느냐? 64비트(8글자)가 다 차버려서ㅠㅠ
mov rax, 0x616c662f706d742f  ; /tmp/fla 문자열의 아스키 코드 -&gt; 리틀 엔디언
push rax                     ; 16진수 두개씩 끊어서 읽어봐
mov rdi, rsp ; rdi = &quot;/tmp/flag&quot; , rdi는 arg0임
xor rsi, rsi  ; rsi = 0; RD_ONLY
xor rdx, rdx  ; rdx = 0
mov rax, 2    ; rax = 2 -&gt; syscall_open
syscall       ; open(&quot;/tmp/flag&quot;, RD_ONLY, NULL)

; read(fd, buf, 0x30) 이번엔 이 부분을 구현할 거임
; – syscall의 반환 값은 rax로 저장, 따라서 open으로 획득한 /tmp/flag의 fd는 rax에 저장.
; – read의 첫 번째 인자를 이 값으로 설정해야 하므로 rax를 rdi에 대입.
; – rsi는 파일에서 읽은 데이터를 저장할 주소를 포인팅, 0x30만큼 읽을 것이므로, rsi에 rsp-0x30을 대입.
; – rdx는 파일로부터 읽어낼 데이터의 길이인 0x30으로 설정.
; – read 시스템콜을 호출하기 위해서 rax를 0으로 설정.
mov rdi, rax  ; rdi = fd
mov rsi, rsp  
sub rsi, 0x30 ; rsi = rsp-0x30 ; buf
mov rdx, 0x30 ; rdx = 0x30     ; len
mov rax, 0x0  ; rax = 0        ; syscall_read
syscall       ; read(fd, buf, 0x30

; write(1, buf, 0x30) 차례
; rsi, rdx는 read에서 사용한 값을 그대로 사용
mov rdi, 1  ; rdi = 1 ; fd = stdout 출력은 stdout으로 할거라서
mov rax, 0x1 ; rax = 1 ; syscall_write
syscall     ; write(fd, buf, 0x30) </code></pre>
<p>📌 fd란? </p>
<ul>
<li>구구절절한 설명</li>
</ul>
<p>유닉스 계열의 운영체제에서 파일에 접근하는 소프트웨어에 제공하는 가상의 접근 제어자</p>
<p>0 : 일반 입력(Standard Input, STDIN) 주로 키보드</p>
<p>1 : 일반 출력(Standard Output, STDOUT) 화면</p>
<p>2 : 일반 오류(Standard Error, STDERR)</p>
<h2 id="execve-셸코드">execve 셸코드</h2>
<p>: 임의의 프로그램을 실행하는 셸코드</p>
<h3 id="system-call">system call</h3>
<p><img src="https://velog.velcdn.com/images/path_finder/post/2ad588b3-06f3-43c3-8cac-fbf5e947dd70/image.png" alt=""></p>
<h3 id="구구절절한-설명">구구절절한 설명</h3>
<p>📌 출처 : 진구</p>
<p>C 언어에서 <strong><code>execve()</code></strong> 함수는 새로운 프로세스를 생성하는 시스템 콜입니다. 이 함수는 기존의 프로세스를 새로운 프로세스로 대체하는데 사용됩니다.</p>
<p><strong><code>execve()</code></strong> 함수는 다음과 같은 선언을 갖습니다.</p>
<pre><code class="language-c">
int execve(const char *filename, char *const argv[], char *const envp[]);</code></pre>
<ul>
<li><strong><code>filename</code></strong>: 실행할 프로그램의 경로와 이름입니다.</li>
<li><strong><code>argv[]</code></strong>: 실행할 프로그램에 전달할 인자값들을 담고 있는 문자열 배열입니다.</li>
<li><strong><code>envp[]</code></strong>: 실행할 프로그램에서 사용할 환경 변수를 담고 있는 문자열 배열입니다.</li>
</ul>
<p><strong><code>execve()</code></strong> 함수를 호출하면 새로운 프로세스가 생성되고 <strong><code>filename</code></strong>으로 지정한 프로그램이 실행됩니다. 실행할 프로그램은 현재 프로세스와는 독립적으로 동작하며, <strong><code>argv[]</code></strong>와 <strong><code>envp[]</code></strong>를 통해 전달된 인자와 환경 변수를 사용할 수 있습니다.</p>
<p><strong><code>execve()</code></strong> 함수는 호출에 성공하면 현재 프로세스의 메모리 영역을 대체하여 새로운 프로그램을 실행합니다. 즉, 현재 프로세스는 새로운 프로그램이 종료될 때까지 더 이상 실행되지 않습니다. 이러한 특징으로 인해, <strong><code>execve()</code></strong> 함수는 다른 프로그램을 실행하는 용도로 주로 사용됩니다.</p>
<p>예를 들어, 다음과 같은 코드는 <strong><code>ls</code></strong> 명령어를 실행하는 예제입니다.</p>
<pre><code class="language-c">
#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;

int main(void) {
    char *argv[] = {&quot;ls&quot;, &quot;-l&quot;, NULL};
    execve(&quot;/bin/ls&quot;, argv, NULL);
    printf(&quot;This line will not be executed\n&quot;);
    return 0;
}</code></pre>
<p>위 코드에서 <strong><code>execve()</code></strong> 함수는 <strong><code>/bin/ls</code></strong> 프로그램을 실행합니다. <strong><code>argv</code></strong> 배열은 <strong><code>ls</code></strong> 프로그램에 전달할 인자를 저장하고 있으며, <strong><code>NULL</code></strong>을 마지막으로 구분합니다. <strong><code>envp</code></strong> 배열은 <strong><code>NULL</code></strong>로 설정하여 환경 변수를 사용하지 않도록 합니다. 실행 결과로는 현재 디렉토리의 파일 목록이 출력됩니다. 이후의 코드는 <strong><code>execve()</code></strong> 함수가 호출되면 실행되지 않습니다.</p>
<h3 id="출처">출처</h3>
<p> 드림핵, 우리 학교 교수님</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Assembly] Assembly - 2]]></title>
            <link>https://velog.io/@path_finder/assembly-2</link>
            <guid>https://velog.io/@path_finder/assembly-2</guid>
            <pubDate>Tue, 18 Apr 2023 12:39:38 GMT</pubDate>
            <description><![CDATA[<p>⭐ 이번 시간은 저번 시간보다 중요한 명령어를 배운다!</p>
<h2 id="스택-stack">스택 Stack</h2>
<h3 id="push">push</h3>
<p><strong>val을 스택 최상단에 쌓음</strong></p>
<p>📌 rsp란?</p>
<p>현재 스택의 최상단 주소를 갖고있는 레지스터</p>
<p><img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3edc9aeb-e424-460b-ad5f-f1d277e9d305/1CAC095C-4B9F-4343-88A3-1B2D1FAF26DE.jpeg" alt="1CAC095C-4B9F-4343-88A3-1B2D1FAF26DE.jpeg"></p>
<pre><code class="language-nasm">rsp -= 8 ; 왜 감소인가? 메모리 방향때문 어쩌구 저쩌
[rsp] = val</code></pre>
<pre><code class="language-nasm">;[Register]
rsp = 0x7fffffffc400

;[Stack]
0x7fffffffc400 | 0x0  &lt;= rsp
0x7fffffffc408 | 0x0

;[Code]
push 0x31337</code></pre>
<pre><code class="language-nasm">;[Register]
rsp = 0x7fffffffc3f8

;[Stack]
0x7fffffffc3f8 | 0x31337 &lt;= rsp 
0x7fffffffc400 | 0x0
0x7fffffffc408 | 0x0</code></pre>
<h3 id="pop">pop</h3>
<p>스택 최상단의 값을 꺼내서 reg에 대입</p>
<pre><code class="language-nasm">rsp += 8 ; 스택 주소는 반대임 그냥 받아들일 것
reg = [rsp-8]</code></pre>
<pre><code class="language-nasm">;[Register]
rax = 0
rsp = 0x7fffffffc3f8

;[Stack]
0x7fffffffc3f8 | 0x31337 &lt;= rsp 
0x7fffffffc400 | 0x0
0x7fffffffc408 | 0x0

;[Code]
pop rax</code></pre>
<pre><code class="language-nasm">;[Register]
rax = 0x31337
rsp = 0x7fffffffc400

;[Stack]
0x7fffffffc400 | 0x0 &lt;= rsp 
0x7fffffffc408 | 0x0</code></pre>
<h2 id="프로시저procedure">프로시저(Procedure)</h2>
<p>📌 프로시저란?</p>
<p>특정 기능을 수행하는 코드 조각, 어셈블리어에 함수같은 거라고 생각하자</p>
<ul>
<li>호출 Call : 프로시저를 부르는 행위</li>
<li>반환 Return : 프로시저에서 돌아오는 것</li>
</ul>
<p>⭐ 호출할때는 프로시저 실행 후 원래 실행 흐름으로 돌아와야 하므로 <strong>call 다음에 명령어 주소</strong>(return address, 반환주소)를 스택에 저장하고 프로시저로 rip를 이동</p>
<h3 id="call">call</h3>
<p><strong>addr에 위치한 프로시져 호출</strong></p>
<pre><code class="language-nasm">push return_address
jmp addr</code></pre>
<pre><code class="language-nasm">;[Register]
rip = 0x400000
rsp = 0x7fffffffc400 

;[Stack]
0x7fffffffc3f8 | 0x0
0x7fffffffc400 | 0x0 &lt;= rsp

;[Code]
0x400000 | call 0x401000  &lt;= rip
0x400005 | mov esi, eax
...
0x401000 | push rbp</code></pre>
<pre><code class="language-nasm">;[Register]
rip = 0x401000
rsp = 0x7fffffffc3f8

;[Stack]
0x7fffffffc3f8 | 0x400005  &lt;= rsp ; 다시 돌아갈 주소가 스택에 쌓임
0x7fffffffc400 | 0x0
[Code]
0x400000 | call 0x401000
0x400005 | mov esi, eax
...
0x401000 | push rbp  &lt;= rip</code></pre>
<h3 id="leave">leave</h3>
<p>스택 프레임 정리</p>
<ul>
<li><p>📌 스택프레임이란? 구구절절한 설명 고고</p>
<p>  스택은 함수별로 자신의 지역변수 또는 연산과정에서 부차적으로 생겨나는 임시 값들을 저장하는 영역입니다. 만약 이 스택 영역을 아무런 구분 없이 사용하게 된다면, 서로 다른 두 함수가 같은 메모리 영역을 사용할 수 있게 됩니다.</p>
<p>  예를 들어 A라는 함수가 B라는 함수를 호출하는데, 이 둘이 같은 스택 영역을 사용한다면, B에서 A의 지역변수를 모두 오염시킬 수 있습니다. 이 경우, B에서 반환한 뒤 A는 정상적인 연산을 수행할 수 없습니다.</p>
<p>  따라서 함수별로 서로가 사용하는 스택의 영역을 명확히 구분하기 위해 스택프레임이 사용됩니다. 우분투 18.04에서 함수는 호출될 때 자신의 스택프레임을 만들고, 반환할 때 이를 정리합니다.</p>
</li>
</ul>
<p>📌 rbp란? </p>
<p>스택의 시작점, 바닥을 가리키고 있는 레지스터</p>
<p>rsp은 꼭대기이므로 반대</p>
<pre><code class="language-nasm">mov rsp, rbp
pop rbp</code></pre>
<pre><code class="language-nasm">;[Register]
rsp = 0x7fffffffc400
rbp = 0x7fffffffc480

;[Stack]
0x7fffffffc400 | 0x0 &lt;= rsp
...
0x7fffffffc480 | 0x7fffffffc500 &lt;= rbp
0x7fffffffc488 | 0x31337 

;[Code]
leave</code></pre>
<pre><code class="language-nasm">;[Register]
rsp = 0x7fffffffc488
rbp = 0x7fffffffc500

;[Stack]
0x7fffffffc400 | 0x0
...
0x7fffffffc480 | 0x7fffffffc500
0x7fffffffc488 | 0x31337 &lt;= rsp
...
0x7fffffffc500 | 0x7fffffffc550 &lt;= rbp</code></pre>
<h3 id="red">red</h3>
<p><strong>return address로 반환</strong></p>
<pre><code class="language-nasm">pop rip</code></pre>
<pre><code class="language-nasm">;[Register]
rip = 0x401008
rsp = 0x7fffffffc3f8
[Stack]
0x7fffffffc3f8 | 0x400005    &lt;= rsp
0x7fffffffc400 | 0

;[Code]
0x400000 | call 0x401000
0x400005 | mov esi, eax
...
0x401000 | mov rbp, rsp  
...
0x401007 | leave
0x401008 | ret  &lt;= rip</code></pre>
<pre><code class="language-nasm">;[Register]
rip = 0x400005
rsp = 0x7fffffffc400
[Stack]
0x7fffffffc3f8 | 0x400005
0x7fffffffc400 | 0x0    &lt;= rsp

;[Code]
0x400000 | call 0x401000
0x400005 | mov esi, eax   &lt;= rip
...
0x401000 | mov rbp, rsp  
...
0x401007 | leave
0x401008 | ret</code></pre>
<h3 id="스택-프레임의-할당과-해제">스택 프레임의 할당과 해제</h3>
<ul>
<li><p>아주 좋은 예시</p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e2ffb53a-723a-48d8-84fc-1add8bfc3025/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.36.21.png" alt="스크린샷 2023-04-06 오전 11.36.21.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2229c51d-4b1c-4522-be64-b82ceb338855/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.37.13.png" alt="스크린샷 2023-04-06 오전 11.37.13.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/c4862686-ede8-4f41-a867-d3023e4674bd/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.37.35.png" alt="스크린샷 2023-04-06 오전 11.37.35.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d8f4a3a5-1bf2-4736-8f1f-3c034e5167b9/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.37.49.png" alt="스크린샷 2023-04-06 오전 11.37.49.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/41a977dc-0277-453c-a45b-b63d1a88ef3b/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.38.06.png" alt="스크린샷 2023-04-06 오전 11.38.06.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e6394cc1-09fa-48b7-9670-48def0a103b2/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.38.21.png" alt="스크린샷 2023-04-06 오전 11.38.21.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f190adc7-1aed-466b-ba2a-2b11c3ab29bc/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.38.32.png" alt="스크린샷 2023-04-06 오전 11.38.32.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/585216e6-3fcc-4c85-ab9b-b32092fe0795/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.38.45.png" alt="스크린샷 2023-04-06 오전 11.38.45.png"></p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/4ff050dd-9851-42f5-898f-63aa8b321266/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.38.59.png" alt="스크린샷 2023-04-06 오전 11.38.59.png"></p>
</li>
</ul>
<h2 id="시스템-콜-system-call">시스템 콜 System Call</h2>
<h3 id="배경">배경</h3>
<ul>
<li><p>구구절절한 설명</p>
<p>  윈도우, 리눅스, 맥 등의 현대 운영체제는 컴퓨터 자원의 효율적인 사용을 위해, 그리고 사용자에게 편리한 경험을 제공하기 위해, 내부적으로 매우 복잡한 동작을 합니다. 운영체제는 연결된 모든 하드웨어 및 소프트웨어에 접근할 수 있으며, 이들을 제어할 수도 있습니다. 그리고 해킹으로부터 이 막강한 권한을 보호하기 위해 커널 모드와 유저 모드로 권한을 나눕니다.</p>
<p>  <strong>커널 모드</strong>는 운영체제가 전체 시스템을 제어하기 위해 시스템 소프트웨어에 부여하는 권한입니다. 파일시스템, 입력/출력, 네트워크 통신, 메모리 관리 등 모든 저수준의 작업은 사용자 모르게 커널 모드에서 진행됩니다. 커널 모드에서는 시스템의 모든 부분을 제어할 수 있기 때문에, 해커가 커널 모드까지 진입하게 되면 시스템은 거의 무방비 상태가 됩니다. 이에 대해서는 나중에 <em>Linux Kernel Exploit</em> 커리큘럼에서 자세히 배울 수 있습니다.</p>
<p>  <strong>유저 모드</strong>는 운영체제가 사용자에게 부여하는 권한입니다. 브라우저를 이용하여 드림핵을 보거나, 유튜브를 시청하는 것, 게임을 하고 프로그래밍을 하는 것 등은 모두 유저 모드에서 이루어집니다. 리눅스에서 루트 권한으로 사용자를 추가하고, 패키지를 내려 받는 행위 등도 마찬가지입니다. 유저 모드에서는 해킹이 발생해도, 해커가 유저 모드의 권한까지 밖에 획득하지 못하기 때문에 해커로 부터 커널의 막강한 권한을 보호할 수 있습니다.</p>
<p>  <strong>시스템 콜(system call, syscall)</strong>은 유저 모드에서 커널 모드의 시스템 소프트웨어에게 어떤 동작을 요청하기 위해 사용됩니다. 소프트웨어 대부분은 커널의 도움이 필요합니다. 예를 들어, 사용자가 <code>cat flag</code>를 실행하면, cat은 flag라는 파일을 읽어서 사용자의 화면에 출력해 줘야 합니다. 그런데 flag는 파일 시스템에 존재하므로 이를 읽으려면 파일시스템에 접근할 수 있어야 합니다. 유저 모드에서는 이를 직접 할 수 없으므로 커널이 <strong>도움</strong>을 줘야 합니다. 여기서, 도움이 필요하다는 요청을 시스템 콜이라고 합니다. 유저 모드의 소프트웨어가 필요한 도움을 요청하면, 커널이 요청한 동작을 수행하여 유저에게 결과를 반환합니다.</p>
<p>  x64아키텍쳐에서는 시스템콜을 위해 <code>syscall</code> 명령어가 있습니다.</p>
<p>  <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b610f2ea-6690-4b1e-bf3c-80d26889da47/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2023-04-06_%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB_11.42.22.png" alt="스크린샷 2023-04-06 오전 11.42.22.png"></p>
</li>
</ul>
<ol>
<li>커널 모드 Kernel mode</li>
<li>유저 모드 User mode</li>
</ol>
<p><strong>시스템 콜 System Call</strong> </p>
<p>유저 모드에서 커널 모드의 시스템 소프트웨어에게 어떤 동작을 요청하기 위해 사용</p>
<p><strong>요청:</strong> rax</p>
<p><strong>인자 순서:</strong> rdi → rsi → rdx → rcx → r8 → r9 → stack</p>
<ul>
<li><p>구구절절한 해석</p>
<p>  오른쪽의 syscall table을 보면, rax가 0x1일 때, 커널에 write 시스템콜을 요청합니다. 이때 rdi, rsi, rdx가 0x1, 0x401000, 0xb 이므로 커널은 write(0x1, 0x401000, 0xb)를 수행하게 됩니다.</p>
<p>  write함수의 각 인자는 출력 스트림, 출력 버퍼, 출력 길이를 나타냅니다. 여기서 0x1은 stdout이며, 이는 일반적으로 화면을 의미합니다. 0x401000에는 Hello World가 저장되어 있고, 길이는 0xb로 지정되어 있으므로, 화면에 Hello World가 출력됩니다.</p>
</li>
</ul>
<pre><code class="language-nasm">;[Register]
rax = 0x1   
rdi = 0x1   
rsi = 0x401000  
rdx = 0xb   

;[Memory]
0x401000 | &quot;Hello Wo&quot;   
0x401008 | &quot;rld&quot;    
[Code]  
syscall

;-----------------;
;output
Hello World</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Assembly] Assembly - 1]]></title>
            <link>https://velog.io/@path_finder/Assembly-Assembly-1</link>
            <guid>https://velog.io/@path_finder/Assembly-Assembly-1</guid>
            <pubDate>Wed, 05 Apr 2023 18:37:58 GMT</pubDate>
            <description><![CDATA[<h1 id="어셈블리어란">어셈블리어란?</h1>
<ul>
<li><p>컴퓨터(CPU)의 기계어와 치환되는 언어</p>
<p>  ⚠️ CPU가 달라지면 어셈블리어도 달라진다!\</p>
</li>
</ul>
<p><strong>배경지식</strong></p>
<ul>
<li><p>CPU에 사용되는 <strong>명령어 집합 구조</strong>는 다양하다</p>
<p>  📌 명령어 집합 구조 : ISA  Instruction Set Architecture</p>
<p>  → 다양한 만큼 어셈블리어도 다양하다.</p>
</li>
</ul>
<p>📌 내 컴퓨터의 환경은 x64아케텍처를 대상으로 하므로 x64만 어셈블리어를 다룬다</p>
<h1 id="어셈블리어의-기본-구조">어셈블리어의 기본 구조</h1>
<aside>
💡 명령어 + 피연산자

</aside>

<pre><code class="language-nasm">mov eax, 3 
; opcode operand1 operand2
; 대입해라 eax에 3을</code></pre>
<h1 id="명령어">명령어</h1>
<h2 id="개요">개요</h2>
<pre><code class="language-nasm">;데이터 이동
mov
lea

;산술 연산
inc
dec
add
sub

;논리 연산
and
or
xor
not

;비교
cmp
test

;분기
jmp, je, jg

;스택
push
pop

;프로시저(Prosedure)
call
ret
leave

;시스템 콜
syscall

; 강교수님 : 기타 등등 많으나 이것만 알아둬도 돼!
; 알아둬야 해</code></pre>
<h3 id="피연산자의-종류">피연산자의 종류</h3>
<ul>
<li><p>상수 ( Immediate Value )</p>
</li>
<li><p>레지스터 ( Register )</p>
</li>
<li><p>메모리 ( Memory )</p>
<p>  📌 메모리 피연산자는 [ 대괄호 ] 로 둘러쌓인 것으로 표현됨</p>
<p>  앞에 크기 지정자(size directive) TYPE PTR 추가</p>
<p>  <strong>TYPE</strong></p>
<ol>
<li><p>BYTE</p>
</li>
<li><p>WORD 워드, 2byte</p>
</li>
<li><p>DWORD 더블 워드, 4byte</p>
</li>
<li><p>QWORD 쿼터 워드, 8byte</p>
<pre><code class="language-nasm">QWORD PTR [0x80488000] ; 0x80488000의 데이터를 8byte만큼 참조
DWRD PTR [0x80488000] ; 0x80488000의 데이터를 4byte만큼 참조
WORD PTR [rax] ; rax가 가리키는 주소에서 데이터를 2byte 만큼 참조</code></pre>
</li>
</ol>
</li>
</ul>
<h2 id="데이터의-이동">데이터의 이동</h2>
<p>어떤 값을 레지스터나 메모리에 옮기도록 지시</p>
<h3 id="mov">mov</h3>
<p>src에 들어있는 값을 dst에 대입</p>
<pre><code class="language-nasm">mov dst, src ; src에 들어있는 값을 dst에 대입
; 순서 헷갈리지 말자! 도착지부터 적는거다.

mov rdi, rsi ; rsi의 값을 rdi에 대입
mov QWORD PTR[rdi], rsi ; rsi의 값을 rdi가 가리키는 주소에 대입
mov QWROD PTR[rdi+8*rcx], rsi ; rsi의 값을 rdi+8*rcx가 가리키는 주소에 대입</code></pre>
<h3 id="lea">lea</h3>
<p>src의 유효주소(Effective Address, EA)를 dst에 저장</p>
<pre><code class="language-nasm">lea dst, src ; src의 유효주소를 dst에 저장

lea rsi, [rbx+8*rcx] ; rbx+8*rcx를 rsi에 대입</code></pre>
<h2 id="산술-연산">산술 연산</h2>
<h3 id="add">add</h3>
<p>dst에 src의 값을 더함</p>
<pre><code class="language-nasm">add dst, src ; dst에 src의 값을 더함

add eax, 3 ; eax += 3
add ax, WORD PTR[rdi] ; ax += *(WORD *)rdi</code></pre>
<h3 id="sub">sub</h3>
<p> dst에서 src의 값을 뺌</p>
<pre><code class="language-nasm">sub dst, src ; dst에서 src의 값을 뺌

sub eax, 3 ; eax -= 3
sub ax, WORD PTR[rdi] ; ax -= *(WORD *)rdi</code></pre>
<h3 id="inc">inc</h3>
<p>op의 값을 1 증가시킴</p>
<pre><code class="language-nasm">inc op ; op의 값을 1 증가시킴

inc eax ; eax += 1</code></pre>
<h3 id="dec">dec</h3>
<p>op의 값을 1 감소 시킴</p>
<pre><code class="language-nasm">dec op ; op의 값을 1 감소 시킴

dec eax ; eax -= 1</code></pre>
<h2 id="논리-연산">논리 연산</h2>
<p>⚠️ <strong>비트단위</strong>로 계산하는 거니까 16진수 → 2진수로 변환하여 계산해야함 귀찮음</p>
<h3 id="and">and</h3>
<p><strong>dst와 src의 비트가 모두 1이면 1, 아니면 0</strong></p>
<pre><code class="language-nasm">and dst, src ; **dst와 src의 비트가 모두 1이면 1, 아니면 0

;[Register]
eax = 0xffff0000
ebx = 0xcafebabe

;[Code]
and eax, ebx

;[Result]
eax = 0xcafe0000**</code></pre>
<h3 id="or">or</h3>
<p><strong>dst와 src의 비트 중 하나라도 1이면 1, 아니면 0</strong></p>
<pre><code class="language-nasm">or dst, src ; **dst와 src의 비트 중 하나라도 1이면 1, 아니면 0

;[Register]
eax = 0xffff0000
ebx = 0xcafebabe

;[Code]
or eax, ebx

;[Result]
eax = 0xffffbabe ; 계산은 시간날때 해보세요**</code></pre>
<h3 id="xor">xor</h3>
<p><strong>dst와 src의 비트가 서로 다르면 1, 같으면 0</strong></p>
<pre><code class="language-nasm">xor dst src ; **dst와 src의 비트가 서로 다르면 1, 같으면 0

;[Register]
eax = 0xffffffff
ebx = 0xcafebabe

;[Code]
xor eax, ebx

;[Result]
eax = 0x35014541**</code></pre>
<h3 id="not">not</h3>
<p><strong>op의 비트 전부 반전</strong></p>
<pre><code class="language-nasm">not op ; op의 비트 전부 반전

;[Register]
eax = 0xffffffff

;[Code]
not eax

;[Result]
eax = 0x00000000</code></pre>
<h2 id="비교">비교</h2>
<p>두 피연산자의 값을 비교하고 플래그를 설</p>
<h3 id="cmp">cmp</h3>
<p><strong>op1과 op2를 비교</strong></p>
<pre><code class="language-nasm">cmp op1, op2 ; op1과 op2를 비교
; 대소를 비교하고 플래그만 세울뿐, 결과를 op1에 저장하지는 않음

;[Code]
1: mov rax, 0xA
2: mov rbx, 0xA
3: cmp rax, rbx ; ZF=1</code></pre>
<h3 id="test">test</h3>
<p><strong>op1과 op2를 비교</strong></p>
<pre><code class="language-nasm">test op1, op2 ; op1과 op2를 비교
; AND연산 취함 결과는 op1에 대입 안함

;[Code]
1: xor rax, rax
2: test rax, rax ; ZF=1
; ZF플래그를 보고 rax가 0이였는지 판단</code></pre>
<h2 id="분기">분기</h2>
<p>rip를 이동시켜 실행 흐름을 바꿈</p>
<p>⚠️ 분기문은 엄청 많지만 여백이 좁아 정리할 수 없다 고로 앞으로 알아가도록</p>
<h3 id="jmp">jmp</h3>
<p><strong>addr로 rip를 이동시킴</strong></p>
<p>📌 rip란?</p>
<p>프로세서가 읽고 있는 현재 명령의 위치를 가리키는 명령 포인터</p>
<pre><code class="language-nasm">jmp addr ; addr로 rip를 이동시킴

;[Code]
1: xor rax, rax
2: jmp 1 ; jump to 1</code></pre>
<h3 id="je">je</h3>
<p><strong>직전에 비교한 두 피연산자가 같으면 점프 (jump if equal)</strong></p>
<pre><code class="language-nasm">je addr ; **직전에 비교한 두 피연산자가 같으면 점프 (jump if equal)**

;[Code]
1: mov rax, 0xcafebabe
2: mov rbx, 0xcafebabe
3: cmp rax, rbx ; rax == rbx
4: je 1 ; jump to 1</code></pre>
<h3 id="jg">jg</h3>
<p><strong>직전에 비교한 두 연산자 중 전자가 더 크면 점프 (jump if greater)</strong></p>
<pre><code class="language-nasm">jg addr ; **직전에 비교한 두 연산자 중 전자가 더 크면 점프 (jump if greater)

;[Code]
1: mov rax, 0x31337
2: mov rbx, 0x13337
3: cmp rax, rbx ; rax &gt; rbx
4: jg 1  ; jump to 1**</code></pre>
<h1 id="까먹을만한-거">까먹을만한 거</h1>
<ul>
<li>대괄호 안에 있으면 주소값이다</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[GDB] GDB 메뉴얼]]></title>
            <link>https://velog.io/@path_finder/GDB-GDB-%EB%A9%94%EB%89%B4%EC%96%BC</link>
            <guid>https://velog.io/@path_finder/GDB-GDB-%EB%A9%94%EB%89%B4%EC%96%BC</guid>
            <pubDate>Wed, 05 Apr 2023 17:46:14 GMT</pubDate>
            <description><![CDATA[<h1 id="기본적인-실행-종료">기본적인 실행, 종료</h1>
<h2 id="실행">실행</h2>
<pre><code class="language-bash">&gt; gdb
// 실행은 참 쉬움</code></pre>
<h2 id="종료">종료</h2>
<pre><code class="language-bash">pwndbg&gt; exit
// 종료도 참 쉬움</code></pre>
<h2 id="gdb-세팅-포맷이-무엇인지-확인하기">gdb 세팅 포맷이 무엇인지 확인하기</h2>
<pre><code class="language-bash">pwndbg&gt; show disassembly-flavor</code></pre>
<p>→ Intel 이면 Intel로 뜸</p>
<p>만약 다른 포맷이면 변경해야 함</p>
<h1 id="써먹어보기">써먹어보기</h1>
<h3 id="예시-코드">예시 코드</h3>
<pre><code class="language-c">// Name : debugee.c
// Compile : gcc -o debugee debugee.c -no-pie
// --------------------------------------------
#include &lt;stdio.h&gt;

int main(void) { 

        int sum = 0;
        int val1 = 1;
        int val2 = 2;

        sum = val1 + val2;
        printf(&quot;1 + 2 = %d\n&quot;, sum);

        return 0;
}</code></pre>
<h3 id="바이너리-파일의-정보-확인하기">바이너리 파일의 정보 확인하기</h3>
<pre><code class="language-bash">&gt; readelf -h debugee // ELF (Executable and Linkable Format</code></pre>
<p>→ 온갖 정보가 다 뜰거임</p>
<p>📌 Entry point address : 프로그램이 실제로 실행되는 주소(16진수)</p>
<h2 id="시잒">시잒!</h2>
<pre><code class="language-bash">&gt; gdb debugee</code></pre>
<p>gdb + 실행파일</p>
<h2 id="진짜-시잒">진짜 시잒!</h2>
<pre><code class="language-bash">pwndbg&gt; start

Temporary breakpoint 1 at 0x40112a # 여기 멈춰 있다는 의미

Temporary breakpoint 1, 0x000000000040112a in main ()
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA # 세그먼트 정보들
────────────────────[ REGISTERS / show-flags off / show-compact-regs off ]─────────────────────
# 레지스터 정보들
*RAX  0x401126 (main) ◂— push rbp
*RBX  0x7fffffffde68 —▸ 0x7fffffffe1ef ◂— &#39;/home/eugene/Workspace/hack/debugee&#39;
*RCX  0x403e00 (__do_global_dtors_aux_fini_array_entry) —▸ 0x4010f0 (__do_global_dtors_aux) ◂— endbr64                                                                                        
*RDX  0x7fffffffde78 —▸ 0x7fffffffe213 ◂— &#39;CLUTTER_IM_MODULE=fcitx&#39;
*RDI  0x1
*RSI  0x7fffffffde68 —▸ 0x7fffffffe1ef ◂— &#39;/home/eugene/Workspace/hack/debugee&#39;
 R8   0x0
*R9   0x7ffff7fcf6a0 (_dl_fini) ◂— push rbp
*R10  0x7ffff7fcb878 ◂— 0xc00120000000e
*R11  0x7ffff7fe18c0 (_dl_audit_preinit) ◂— mov eax, dword ptr [rip + 0x1b552]
 R12  0x0
*R13  0x7fffffffde78 —▸ 0x7fffffffe213 ◂— &#39;CLUTTER_IM_MODULE=fcitx&#39;
*R14  0x403e00 (__do_global_dtors_aux_fini_array_entry) —▸ 0x4010f0 (__do_global_dtors_aux) ◂— endbr64                                                                                        
*R15  0x7ffff7ffd020 (_rtld_global) —▸ 0x7ffff7ffe2e0 ◂— 0x0
*RBP  0x7fffffffdd50 ◂— 0x1 # 레지스터 외워라 좀;
*RSP  0x7fffffffdd50 ◂— 0x1
*RIP  0x40112a (main+4) ◂— sub rsp, 0x10
─────────────────────────────[ DISASM / x86-64 / set emulate on ]──────────────────────────────
 ► 0x40112a &lt;main+4&gt;     sub    rsp, 0x10 # 여기서 멈춰 있다고 친절하게 알려줌
   0x40112e &lt;main+8&gt;     mov    dword ptr [rbp - 4], 0
   0x401135 &lt;main+15&gt;    mov    dword ptr [rbp - 8], 1
   0x40113c &lt;main+22&gt;    mov    dword ptr [rbp - 0xc], 2
   0x401143 &lt;main+29&gt;    mov    edx, dword ptr [rbp - 8]
   0x401146 &lt;main+32&gt;    mov    eax, dword ptr [rbp - 0xc]
   0x401149 &lt;main+35&gt;    add    eax, edx
   0x40114b &lt;main+37&gt;    mov    dword ptr [rbp - 4], eax
   0x40114e &lt;main+40&gt;    mov    eax, dword ptr [rbp - 4]
   0x401151 &lt;main+43&gt;    mov    esi, eax
   0x401153 &lt;main+45&gt;    lea    rax, [rip + 0xeaa]
───────────────────────────────────────────[ STACK ]───────────────────────────────────────────
00:0000│ rbp rsp 0x7fffffffdd50 ◂— 0x1
01:0008│         0x7fffffffdd58 —▸ 0x7ffff7df318a (__libc_start_call_main+122) ◂— mov edi, eax
02:0010│         0x7fffffffdd60 ◂— 0x0
03:0018│         0x7fffffffdd68 —▸ 0x401126 (main) ◂— push rbp
04:0020│         0x7fffffffdd70 ◂— 0x100000000
05:0028│         0x7fffffffdd78 —▸ 0x7fffffffde68 —▸ 0x7fffffffe1ef ◂— &#39;/home/eugene/Workspace/hack/debugee&#39;
06:0030│         0x7fffffffdd80 —▸ 0x7fffffffde68 —▸ 0x7ffffffhack/debugee&#39;
07:0038│         0x7fffffffdd88 ◂— 0x2181d7828d77fade
─────────────────────────────────────────[ BACKTRACE ]────────
 ► f 0         0x40112a main+4
   f 1   0x7ffff7df318a __libc_start_call_main+122
   f 2   0x7ffff7df3245 __libc_start_main+133
   f 3         0x401061 _start+33 # entry point + 33 byte
                                                                    # 실제 프로그램이 시작하는 시점은 main이 아니다!
──────────────────────────────────────────────────────────────
pwndbg&gt;</code></pre>
<h2 id="break-point-잡기">break point 잡기</h2>
<p>메인에 걸어두는 습관이 있으면 좋다.</p>
<p>여러개 걸어둘 수 있다. 그리고 순서도 상관 없다.</p>
<pre><code class="language-bash">pwndbg&gt; break *main # 메인 함수에 브레이크 걸라는 명령
Breakpoint 1 at 0x401126 # 메인 함수에서 break 걸었다!</code></pre>
<h3 id="run-r도-가능">run (r도 가능)</h3>
<p>중단점 설정된곳까지 실행</p>
<pre><code class="language-bash">pwndbg&gt; run # 프로그램 실행
Starting program: /home/eugene/Workspace/hack/debugee 
[Thread debugging using libthread_db enabled]
Using host libthread_db library &quot;/lib/x86_64-linux-gnu/libthread_db.so.1&quot;.                                                  

Breakpoint 1, 0x0000000000401126 in main ()
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
────[ REGISTERS / show-flags off / show-compact-regs off ]────
*RAX  0x401126 (main) ◂— push rbp
*RBX  0x7fffffffde68 —▸ 0x7fffffffe1ef ◂— &#39;/home/eugene/Workspace/hack/debugee&#39;
*RCX  0x403e00 (__do_global_dtors_aux_fini_array_entry) —▸ 0x4010f0 (__do_global_dtors_aux) ◂— endbr64                      
*RDX  0x7fffffffde78 —▸ 0x7fffffffe213 ◂— &#39;CLUTTER_IM_MODULE=fcitx&#39;
*RDI  0x1
*RSI  0x7fffffffde68 —▸ 0x7fffffffe1ef ◂— &#39;/home/eugene/Workspace/hack/debugee&#39;
 R8   0x0
*R9   0x7ffff7fcf6a0 (_dl_fini) ◂— push rbp
*R10  0x7ffff7fcb878 ◂— 0xc00120000000e
*R11  0x7ffff7fe18c0 (_dl_audit_preinit) ◂— mov eax, dword ptr [rip + 0x1b552]                                              
 R12  0x0
*R13  0x7fffffffde78 —▸ 0x7fffffffe213 ◂— &#39;CLUTTER_IM_MODULE=fcitx&#39;
*R14  0x403e00 (__do_global_dtors_aux_fini_array_entry) —▸ 0x4010f0 (__do_global_dtors_aux) ◂— endbr64                      
*R15  0x7ffff7ffd020 (_rtld_global) —▸ 0x7ffff7ffe2e0 ◂— 0x0
*RBP  0x1
*RSP  0x7fffffffdd58 —▸ 0x7ffff7df318a (__libc_start_call_main+122) ◂— mov edi, eax                                         
*RIP  0x401126 (main) ◂— push rbp
─────────────[ DISASM / x86-64 / set emulate on ]─────────────
 ► 0x401126 &lt;main&gt;       push   rbp # 여기서 멈췄다! 우리가 원했던 메인함수에 브레이크 걸림
   0x401127 &lt;main+1&gt;     mov    rbp, rsp
   0x40112a &lt;main+4&gt;     sub    rsp, 0x10
   0x40112e &lt;main+8&gt;     mov    dword ptr [rbp - 4], 0
   0x401135 &lt;main+15&gt;    mov    dword ptr [rbp - 8], 1
   0x40113c &lt;main+22&gt;    mov    dword ptr [rbp - 0xc], 2
   0x401143 &lt;main+29&gt;    mov    edx, dword ptr [rbp - 8]
   0x401146 &lt;main+32&gt;    mov    eax, dword ptr [rbp - 0xc]
   0x401149 &lt;main+35&gt;    add    eax, edx
   0x40114b &lt;main+37&gt;    mov    dword ptr [rbp - 4], eax
   0x40114e &lt;main+40&gt;    mov    eax, dword ptr [rbp - 4]
──────────────────────────[ STACK ]───────────────────────────
00:0000│ rsp 0x7fffffffdd58 —▸ 0x7ffff7df318a (__libc_start_call_main+122) ◂— mov edi, eax                                  
01:0008│     0x7fffffffdd60 ◂— 0x0
02:0010│     0x7fffffffdd68 —▸ 0x401126 (main) ◂— push rbp
03:0018│     0x7fffffffdd70 ◂— 0x100000000
04:0020│     0x7fffffffdd78 —▸ 0x7fffffffde68 —▸ 0x7fffffffe1ef ◂— &#39;/home/eugene/Workspace/hack/debugee&#39;                    
05:0028│     0x7fffffffdd80 —▸ 0x7fffffffde68 —▸ 0x7fffffffe1ef ◂— &#39;/home/eugene/Workspace/hack/debugee&#39;                    
06:0030│     0x7fffffffdd88 ◂— 0xc884d300c9241961
07:0038│     0x7fffffffdd90 ◂— 0x0
────────────────────────[ BACKTRACE ]─────────────────────────
 ► f 0         0x401126 main
   f 1   0x7ffff7df318a __libc_start_call_main+122
   f 2   0x7ffff7df3245 __libc_start_main+133
   f 3         0x401061 _start+33
──────────────────────────────────────────────────────────────</code></pre>
<h3 id="continue">continue</h3>
<pre><code class="language-bash">pwndbg&gt; continue # 얘를 입력하면 프로그램이 끝까지 실행됨
Continuing.
1 + 2 = 3
[Inferior 1 (process 17990) exited normally]</code></pre>
<h2 id="gdb-명령어-요약">gdb 명령어 요약</h2>
<ul>
<li>b : break</li>
<li>c : continue</li>
<li>r : run</li>
<li>si : step into ( 함수로 들어감 )</li>
<li>ni next instruction ( 함수를 넘어감 )</li>
<li>i : info</li>
<li>k : kill</li>
<li>pd : pdisas</li>
</ul>
<h3 id="disassemble">disassemble</h3>
<p>특정 부분의 어셈블리 코드를 볼 수 있다.</p>
<p>유사한 명령어 : u, nearpc, pdisassemble</p>
<pre><code class="language-bash">pwndbg&gt; disassemble main
Dump of assembler code for function main:
   0x0000000000401126 &lt;+0&gt;:     push   rbp
   0x0000000000401127 &lt;+1&gt;:     mov    rbp,rsp
   0x000000000040112a &lt;+4&gt;:     sub    rsp,0x10
   0x000000000040112e &lt;+8&gt;:     mov    DWORD PTR [rbp-0x4],0x0
   0x0000000000401135 &lt;+15&gt;:    mov    DWORD PTR [rbp-0x8],0x1
   0x000000000040113c &lt;+22&gt;:    mov    DWORD PTR [rbp-0xc],0x2
   0x0000000000401143 &lt;+29&gt;:    mov    edx,DWORD PTR [rbp-0x8]
   0x0000000000401146 &lt;+32&gt;:    mov    eax,DWORD PTR [rbp-0xc]
   0x0000000000401149 &lt;+35&gt;:    add    eax,edx
   0x000000000040114b &lt;+37&gt;:    mov    DWORD PTR [rbp-0x4],eax
   0x000000000040114e &lt;+40&gt;:    mov    eax,DWORD PTR [rbp-0x4]
   0x0000000000401151 &lt;+43&gt;:    mov    esi,eax
   0x0000000000401153 &lt;+45&gt;:    lea    rax,[rip+0xeaa]        # 0x402004                                                    
   0x000000000040115a &lt;+52&gt;:    mov    rdi,rax
   0x000000000040115d &lt;+55&gt;:    mov    eax,0x0
   0x0000000000401162 &lt;+60&gt;:    call   0x401030 &lt;printf@plt&gt;
   0x0000000000401167 &lt;+65&gt;:    mov    eax,0x0
   0x000000000040116c &lt;+70&gt;:    leave
   0x000000000040116d &lt;+71&gt;:    ret
End of assembler dump.</code></pre>
<h3 id="ni-si">ni, si</h3>
<p>공통점 : 어세믈리 명령어를 한줄 씩 실행</p>
<p>차이점 :</p>
<p>ni : 서브루틴의 내부로 들어가지 않음</p>
<p>si : 서브루틴의 내부로 진입</p>
<pre><code class="language-bash">pwndbg&gt; b *main+40
Breakpoint 2 at 0x40114e
pwndbg&gt; b *main
Breakpoint 3 at 0x401126
# 일단은 두 군데에 브레이크 걸어둠
# si, ni 사용할때마다 한칸씩 앞으로 감
# continue는 브레이크 걸린 부분까지 하이패스</code></pre>
<p>📌 si로 진입 후 함수 끝까지 한번에 실행하 : finish</p>
<h3 id="메모리-값-확인">메모리 값 확인</h3>
<ul>
<li><blockquote>
<p>x/숫자단위포맷 시작주소</p>
</blockquote>
</li>
<li><blockquote>
<p>x/10gx $rsp</p>
</blockquote>
<p>  → rsp에서 80바이트를 8바이트씩 hex형식으로 출력</p>
</li>
</ul>
<p>📌 o : 8진법</p>
<p>x : 16진법</p>
<p>u : 10진법</p>
<p>t : 2진법</p>
<p>b : 1byte 단위</p>
<p>h : 2byte 단위 half word</p>
<p>w : 4byte 단위 word</p>
<p>g : 8byte 단위 giant</p>
<p>i : 역어셈블된 명령어의 명령 메모리를 볼 수 있음</p>
<p>c : ASCII 표의 바이트를 자동으로 볼 수 있음</p>
<p>S : 문자 데이터의 전체 문자열을 보여줌</p>
<pre><code class="language-bash">pwndbg&gt; x/10gx $rsp # rsp에서 80byte를 8byte씩 hex형식으로 출력
0x7fffffffdd98: 0x00007ffff7df318a      0x0000000000000000
0x7fffffffdda8: 0x0000000000401126      0x0000000100000000
0x7fffffffddb8: 0x00007fffffffdea8      0x00007fffffffdea8
0x7fffffffddc8: 0xe93492b27d999a21      0x0000000000000000
0x7fffffffddd8: 0x00007fffffffdeb8      0x0000000000403e00</code></pre>
<pre><code class="language-bash">pwndbg&gt; x/5i $rip # rip부터 5줄의 어셈블리 명령어 출력
=&gt; 0x401126 &lt;main&gt;:     push   rbp
   0x401127 &lt;main+1&gt;:   mov    rbp,rsp
   0x40112a &lt;main+4&gt;:   sub    rsp,0x10
   0x40112e &lt;main+8&gt;:   mov    DWORD PTR [rbp-0x4],0x0
   0x401135 &lt;main+15&gt;:  mov    DWORD PTR [rbp-0x8],0x1</code></pre>
<pre><code class="language-bash">pwndbg&gt; x/s 0x400000 # 특정 주소의 문자열 출력
0x400000:       &quot;\177ELF\002\001\001&quot;</code></pre>
<h3 id="변수값-확인--print">변수값 확인 : print</h3>
<pre><code class="language-bash">pwndbg&gt; print args
$1 = 2

pwndbg&gt; print argv[0]
$2 = 0x7fffffffe20b &quot;/home/eugene/Workspace/hack/bugfile&quot;</code></pre>
<h3 id="레지스터-값-확인--info-reg">레지스터 값 확인 : info reg</h3>
<pre><code class="language-bash">pwndbg&gt; info reg # 레지스터 전체값 
rax            0x555555555149      93824992235849
rbx            0x7fffffffde88      140737488346760
rcx            0x555555557dd8      93824992247256
rdx            0x7fffffffdea0      140737488346784
rsi            0x7fffffffde88      140737488346760
rdi            0x2                 2
rbp            0x7fffffffdd70      0x7fffffffdd70
rsp            0x7fffffffdd50      0x7fffffffdd50
r8             0x0                 0
r9             0x7ffff7fcf6a0      140737353938592
r10            0x7ffff7fcb878      140737353922680
r11            0x7ffff7fe18c0      140737354012864
r12            0x0                 0
r13            0x7fffffffdea0      140737488346784
r14            0x555555557dd8      93824992247256
r15            0x7ffff7ffd020      140737354125344
rip            0x555555555158      0x555555555158 &lt;main+15&gt;
eflags         0x206               [ PF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0</code></pre>
<pre><code class="language-bash">pwndbg&gt; info reg $rsp # 특정 레지스터 값
rsp            0x7fffffffdd50      0x7fffffffdd50</code></pre>
<h3 id="스택-확인">스택 확인</h3>
<ul>
<li><blockquote>
<p>x/[조회하는 메모리 범위]xw[조회하는 메모리 지점]</p>
</blockquote>
</li>
</ul>
<pre><code class="language-bash">0x7fffffffdd50: 0xffffde88      0x00007fff      0x00000000      0x00000002
0x7fffffffdd60: 0x00000000      0x00000000      0x00000000      0x00000000
0x7fffffffdd70: 0x00000002      0x00000000      0xf7df318a      0x00007fff
0x7fffffffdd80: 0x00000000      0x00000000      0x55555149      0x00005555
0x7fffffffdd90: 0x00000000      0x00000002      0xffffde88      0x00007fff
0x7fffffffdda0: 0xffffde88      0x00007fff      0xc2fecbe3      0x6cd326ff
0x7fffffffddb0: 0x00000000      0x00000000      0xffffdea0      0x00007fff
0x7fffffffddc0: 0x55557dd8      0x00005555      0xf7ffd020      0x00007fff</code></pre>
<h1 id="후기">후기</h1>
<p>어렵지만 재밌다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Numpy] 배열 생성]]></title>
            <link>https://velog.io/@path_finder/Numpy-%EB%8B%A4%EB%A3%A8%EA%B8%B0</link>
            <guid>https://velog.io/@path_finder/Numpy-%EB%8B%A4%EB%A3%A8%EA%B8%B0</guid>
            <pubDate>Wed, 05 Apr 2023 07:47:56 GMT</pubDate>
            <description><![CDATA[<h2 id="numpy-배열과-텐서">Numpy 배열과 텐서</h2>
<h3 id="배열-생성">배열 생성</h3>
<ul>
<li><p>float 타입의 vector 생성</p>
<pre><code class="language-python">import numpay as np //  Numpy 호출
test_array = np.array([1, 4, 5, 8], float) 
// 생성할 데이터, 데이터 타입</code></pre>
</li>
<li><p>m x n 형태의 행렬</p>
<pre><code class="language-python">import numpy as np
test_list = [[1,4,5,8],[1,4,5,8]]
np.array(test_list, float) 
</code></pre>
</li>
</ul>
<p>test_array2 = [[1,4,5,8],[1,4,5]] // 모든 데이터가 채워져 있어야 함
np.array(test_list2, float) // ValueError</p>
<pre><code>⚠️ 동적 타이핑은 지원하지 않음 ⚠️
```python
import numpy as np
test_array = np.array([1,4,5,8], float)
test_array

// output
array([1.,4.,5.,8.])</code></pre><h4 id="numpy-array와-python-list간의-차이점은">Numpy array와 Python list간의 차이점은?</h4>
<p>Python list : 메모리상에 연속적으로 배열되어 있는 것이 아니라 <strong>해당 값의 메모리 주소</strong>만 연속적으로 배열
Numpy array : <strong>실제 값을 메모리상에서 연속적으로 나열</strong>, 각 값들의 메모리 크기가 동일해야 함</p>
<h3 id="배열-생성-예시">배열 생성 예시</h3>
<pre><code class="language-python">import numpy as np
test_array = np.array([1,3,5,&quot;8&quot;], float)
print(test_array)

// output
[1. 3. 5. 8.]</code></pre>
<h4 id="자동-형-변환">자동 형 변환</h4>
<pre><code class="language-python">print(type(test_array[3]) # 실수형으로 자동 형 변환 실시

# output
&lt;class &#39;nupy.float64&#39;&gt;</code></pre>
<h4 id="배열-전체의-데이터-타입-반환-dtype">배열 전체의 데이터 타입 반환 .dtype</h4>
<pre><code class="language-python">print(test_array.dtype) 
# output
float64 # 메모리에 8바이트씩 할당

# 정수형 Numpy 배열로 생성
np.array([[1,2,3.5], [4, 5, 6.4]], dtype=int) 
# output
array([[1,2,3],
       [4,5,6]])</code></pre>
<h4 id="배열의-구조shape-반환-shape">배열의 구조(Shape) 반환 .shape</h4>
<p>📌 배열의 구조(shape)
배열 객체의 차원 구성이 어떠한지 나타내는 함수</p>
<pre><code class="language-python">print(test_array.shape)
# output
(4,) # 튜플 형태
# 1차원의 랭크를 가지면서 4개의 요소를 가지고 있는 Numpy 배열

matrix = [[1,2,3,5], [1,2,5,7], [2,4,6,7]]
np.array(matrix, int).shape
# output
(3, 4)
# 앞의 값은 행(row), 뒤의 값은 열(column)이다.
# 2차원 랭크를 가지면서 3행 4열의 요소를 가지고 있는 Numpy배열</code></pre>
<h4 id="랭크-반환-ndim">랭크 반환 .ndim</h4>
<h4 id="배열의-모든-데이터-개수-size">배열의 모든 데이터 개수 .size</h4>
<h4 id="배열-요소의-크기-반환-itemsize">배열 요소의 크기 반환 .itemsize</h4>
<p>ㅇ</p>
]]></description>
        </item>
    </channel>
</rss>