Dydaktyka
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Ćwiczenia 10, grupa śr. 17-19, 26 kwietnia 2023 ###### tags: `ASK23` `ćwiczenia` `pwit` ## Deklaracje Gotowość rozwiązania zadania należy wyrazić poprzez postawienie X w odpowiedniej kolumnie! Jeśli pożądasz zreferować dane zadanie (co najwyżej jedno!) w trakcie dyskusji oznacz je znakiem ==X== na żółtym tle. **UWAGA: Tabelkę wolno edytować tylko wtedy, gdy jest na zielonym tle!** :::danger | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | | ----------------------:| --- | --- | --- | --- | --- | --- | --- | --- | --- | | Kamila Goszcz | | x | |==x==| x | | | | | | Mateusz Materek | X | X | | X |==X==| | X | | | ::: :::info **Uwaga:** Po rozwiązaniu zadania należy zmienić kolor nagłówka na zielony. ::: ## Zadanie 1 :::success Autor: Mateusz Materek ::: ![](https://hackmd.io/_uploads/ryCHpo_E3.png) ``` gcc -ggdb -Og -Wall -g0 -fno-common -S -o data.s data.c -ggdb -> Produce debugging information for use by GDB. This means to use the most expressive format available (DWARF, stabs, or the native format if neither of those are supported), including GDB extensions if at all possible. -Og -> Optimize debugging experience. -Og should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience. -Wall -> This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. -fno-common -> The default is -fno-common, which specifies that the compiler places uninitialized global variables in the BSS section of the object file. -S -> generuj plik asm -o -> nazwa pliku wyjściowego ``` Dyrektywy asemblera w kodzie: - `.globl` -> **modyfikuje tablicę symboli** .global makes the symbol visible to ld. If you define symbol in your partial program, its value is made available to other partial programs that are linked with it. Otherwise, symbol takes its attributes from a symbol of the same name from another file linked into the same program. - `.data` -> **przełącza sekcje** .data tells as to assemble the following statements onto the end of the data subsection numbered subsection (which is an absolute expression). If subsection is omitted, it defaults to zero. - `.align` -> **modyfikuje nagłówek** Pad the location counter (in the current subsection) to a particular storage boundary. The first expression (which must be absolute) is the alignment required, as described below. If this expression is omitted then a default value of 0 is used, effectively disabling alignment requirements. - `.type` -> This directive is used to set the type of a symbol. This sets the type of symbol name to be either a function symbol or an object symbol. There are five different syntaxes supported for the type description field, in order to provide compatibility with various other assemblers. - STT_FUNC (function) -> Mark the symbol as being a function name. - STT_GNU_IFUNC (gnu_indirect_function)-> Mark the symbol as an indirect function when evaluated during reloc processing. (This is only supported on assemblers targeting GNU systems). - STT_OBJECT (object) -> Mark the symbol as being a data object. - STT_TLS (tls_object) -> Mark the symbol as being a thread-local data object. - STT_COMMON (common) -> Mark the symbol as being a common data object. - STT_NOTYPE (notype) -> Does not mark the symbol in any way. It is supported just for completeness. - gnu_unique_object -> Marks the symbol as being a globally unique data object. The dynamic linker will make sure that in the entire process there is just one symbol with this name and type in use. (This is only supported on assemblers targeting GNU systems). - `.size` -> This directive is used to set the size associated with a symbol. - `.value` -> The .value directive generates an initialized word (16-bit, two's complement value) for each expression into the current section. Each expression must be a 16-bit integer value. The .value directive is not valid for the .bss section. - `.section` -> **dopisuje do sekcji** Use the .section directive to assemble the following code into a section named name. - `.string` -> Copy the characters in str to the object file - `.bss` -> **przełącza sekcję** .bss tells as to assemble the following statements onto the end of the bss section. - `.zero` -> This directive emits size 0-valued bytes. size must be an absolute expression. - `.quad` -> .quad expects zero or more bignums, separated by commas. For each bignum, it emits an 8-byte integer. If the bignum won’t fit in 8 bytes, it prints a warning message; and just takes the lowest order 8 bytes of the bignum. - `.long` -> (same as int) Expect zero or more expressions, of any section, separated by commas. For each expression, emit a number that, at run time, is the value of that expression. The byte order and bit size of the number depends on what kind of target the assembly is for. ## Zadanie 2 :::success Autor: Kamila Goszcz ::: ![](https://hackmd.io/_uploads/BkzRCmtVh.png) ### Definicje symboli: Linia 3 - .type ### Czemu assembler nie może wygenerować ostatecznego ciągu bajtów? Ponieważ pliki *.c nie zostały jeszcze skonsolidowane i nie znają offsetu który powstanie między funkcjami po ich połączeniu, tworzona jest zmienna, w której miejsce zostanie wpisany offset ## Zadanie 3 :::danger Autor: ::: ## Zadanie 4 :::success Autor: Kamila Goszcz ::: ![](https://hackmd.io/_uploads/rJxw8VYE2.png) ### Przepełnienie bufora Polega na zapisaniu większej ilości danych do pamięci niż ilość zarezerwowanego na ten cel miejsca. Prowadzi to do nadpisania danych znajdujących się bezpośrednio za wyznaczonym miejscem. ### Programowanie zorientowane na powroty Technika wykorzystująca lukę w zabezpieczeniach komputera , która umożliwia atakującemu wykonanie kodu w obecności zabezpieczeń, takich jak ochrona przestrzeni wykonywalnej i podpisywanie kodu . W tej technice atakujący przejmuje kontrolę nad stosem wywołań w celu przejęcia przepływu sterowania programem, a następnie wykonuje starannie wybrane sekwencje instrukcji maszynowych , które są już obecne w pamięci maszyny, zwane „gadżetami”. Każdy gadżet zwykle kończy się instrukcją powrotu i znajduje się w podprogramie w ramach istniejącego programu i / lub kodu biblioteki współdzielonej. Połączone ze sobą gadżety umożliwiają atakującemu wykonywanie dowolnych operacji na maszynie wykorzystującej mechanizmy obronne, które udaremniają prostsze ataki. ### Wyszukiwanie adresów: ``` objdump -d ropex | grep "gadget": adres - 401d7b little endian - 7b1d 4000 ``` ``` objdump -d ropex | grep "syscall": adres - 47a88d little endian - 8da8 4700 ``` ### Tłumaczenie: `xxd -r ropex.in.txt >ropex.in` ## Zadanie 5 :::success Autor: Mateusz Materek ::: ![](https://hackmd.io/_uploads/r1gFgQKVh.png) **Kanarek**: szczególne miejsce w pamięci (zaraz za końcem ramki stosu) z losową wartością której naruszenie wskazuje na naruszenie bezpieczeństwa Szczególne miejsce w pamięci: `%fs:0x28` - to tu przetrzymywany jest kanarek Parę przykładowych wartości kanarka: ``` 0x89d04134039b7600 0xd1968733b1fe6d00 0x7501dd9e3b334d00 ``` *(reszta w Terminalu)* ## Zadanie 6 :::danger Autor: ::: ## Zadanie 7 :::success Autor: Mateusz Materek ::: ![](https://hackmd.io/_uploads/HydAo7tV2.png) **Konsolidator dynamiczny** -> jego zadaniem jest załadowanie pliku, który używa bibliotek współdzielonych; konsolidator odnajduje potrzebne odwołania i wiąże je z symbolami z programu *(np. potrafi zlokalizować kod odpowiedzialny za funkcję `printf` wykorzystywaną w naszym programie we (współdzielonej) bibliotece standardowej języka C i powiązać wystąpienie symbolu `printf` w naszym programie z kodem procedury zawartym w innym pliku)* **Etapy pracy ld**: 1. Startup -> kernel przekazuje kontrolę nie do programu, a do linkera (określonego w sekcji .init) 2. Finding objects -> każdy plik może zawierać sekcję z potrzebnymi bibliotekami współdzielonymi. Trzeba je znaleźć! (mogą być określone przez użytkownika - np. ld.so.conf, przez wpisy DT_RUNPATH w sekcji .dynamic, domyślne ścieżki `/usr/lib`) 3. Relocation -> ld albo zrobi natychmiastową relokację, albo wiązanie zostanie odroczone w czasie dzięki Procedure Linkage Table (PLT) (metoda leniwa jest domyślna) 4. Initialization -> zwrócenie kontroli do programu *(reszta w Terminalu)* ## Zadanie 8 :::danger Autor: ::: ## Zadanie 9 :::danger Autor: :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully