Diogo Fonte
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    # Logbook 4 ## Task 1 - Usamos os comandos printenv e env para imprimir as variáveis de ambiente. Para imprimir uma variável em concreto, usamos o comando printenv seguido do nome da variável de ambiente ou "env | grep" também seguido pelo nome da variável. - Executamos os comandos export e unset para ativar e desativar as variáveis de ambiente. Isto tudo feito na bash. Printenv:![](https://i.imgur.com/W5N1TKh.png) Env:![](https://i.imgur.com/4e9lhh2.png) Printenv PWD: ![](https://i.imgur.com/mH41xV4.png) Export:![](https://i.imgur.com/6fkGIjO.png) ## Task 2 O objetivo desta tarefa é saber se um processo filho herda as variáveis de ambiente do seu pai. 1) Compilamos e executamos o seguinte código: ``` #include <unistd.h> #include <stdio.h> #include <stdlib.h> extern char **environ; void printenv(){ int i = 0; while (environ[i] != NULL) { printf("%s\n", environ[i]); i++; } } void main() { pid_t childPid; switch(childPid = fork()) { case 0: /* child process */ printenv(); ➀ exit(0); default: /* parent process */ //printenv(); ➁ exit(0); } } ``` 2) Posto isto comentamos o primeiro printenv() e descomentamos o segundo. 3) Ambos os resultados foram guardados em ficheiros e com o comando diff comparamos. ##### Conclusões Não houve diferenças no *output* (presente no ficheiro file2) de ambos os passos, portanto as variáveis de ambientes do processo pai são herdadas pelo processo filho. ## Task 3 O objetivo de estudo desta tarefa é ficar a saber como as variáveis de ambiente são afetadas quando um novo programa é executado via execve(). Esta função chama uma *system call* para carregar um comando e executá-lo, mas nunca retorna. Nenhum processo é criado, e em vez disso os dados do processo que fez a chamada são sobrescritos. A função execve() corre o programa novo dentro do processo de chamada. 1) Compilamos e corremos o seguinte código: ``` #include <unistd.h> extern char **environ; int main(){ char *argv[2]; argv[0] = "/usr/bin/env"; argv[1] = NULL; execve("/usr/bin/env", argv, NULL); ➀ return 0 ; } ``` Neste ponto não houve nenhum *output*. 2) Mudamos a linha com o apontamento "1" para: ``` execve("/usr/bin/env", argv, environ); ``` O *output*, com esta alteração no programa, está no ficheiro file3. #### Conclusões As variáveis de ambiente são automaticamente herdadas pelo novo programa. No primeiro ponto passamos NULL como argumento, em vez da matriz environ como no segundo ponto. Com a correção e adição de environ no parâmetro da função execve, conseguimos guardar as variáveis de ambiente (do processo pai) e imprimi-las. ## Task 4 Nesta tarefa o estudo é sobre como as variáveis de ambiente são afetadas quando um programa novo é executado pela função system. Esta função é utilizada para executar um comando e executa "/bin/sh -c comando", ou seja, executa /bin/sh e pede à shell para executar o comando, ao contrário da função execve que executa diretamente o comando. A função system usa a função execl na sua implementação para executar /bin/sh. A função execl chama execve() e passa como argumento o *array* das variáveis de ambiente. Portanto, ao usar system(), as variáveis de ambiente, do processo que faz a chamada, são passadas para o novo programa /bin/sh. 1) Compilamos e corremos o seguinte código: ``` #include <stdio.h> #include <stdlib.h> int main(){ system("/usr/bin/env"); return 0 ; } ``` O resultado está no file4. Como esperado, o *output* as variáveis de ambiente do processo pai. ## Task 5 Set-UID é um mecanismo de segurança importante em sistemas operativos UNIX. Quando se corre um programa Set-UID ele assume privilégios de *owner*. Dá para fazer imensas coisas interessantes utilizando Set-UID, mas é bastante arriscado, porque aumenta os privilégios do utilizador. Apesar dos comportamentos de programas Set-UID serem decididos pela lógica do programa em si, os utilizadores podem afetá-los através da manipulação das variáveis de ambiente. 1) Compilamos o seguinte código, que imprime todas as variáveis de ambiente do processo atual: ``` #include <stdio.h> #include <stdlib.h> extern char **environ; int main(){ int i = 0; while (environ[i] != NULL) { printf("%s\n", environ[i]); i++; } } ``` 2) Mudamos a propriedade do programa para *root* e tornámos-lo um programa Set-UID e executamos os seguintes comandos: ``` $ sudo chown root a.out $ sudo chmod 4755 a.out ``` 3) Utilizamos o comando export para alterar as variáveis de ambiente PATH, LD_LIBRARY_PATH e criamos a variável ANY_NAME. Os nossos resultados e execuções estão nos seguintes *screenshots*: ![](https://i.imgur.com/hAJ66SS.png) ![](https://i.imgur.com/Fy39AFp.png) ![](https://i.imgur.com/iLKtF0H.png) #### Conclusões Após executarmos todos os passos descritos anteriormente, conseguimos visualizar as três variáveis de ambiente mencionadas acima com os valores que inserimos. ## Task 6 Chamar a função system num programa Set-UID é bastante perigoso, por causa do programa da shell ser invocado. O comportamento do programa da shell pode ser afetado pelas variáveis de ambiente, como por exemplo, a PATH. As variáveis de ambiente são fornecidas pelo utilizador, e este pode ser malicioso. Ao alterar estas variáveis os utilizadores conseguem controlar o comportamento do programa Set-UID. 1) O seguinte código cria um programa "myls".c. No código apenas é utilizado o caminho do comando ls relativo ao diretório, em vez do caminho absoluto, daí poderem ser gerados problemas. Compilamos, alteramos a propriedade para *owner* e tornámos-lo um programa SET-UID. ``` #include <stdio.h> #include <stdlib.h> int main(){ system("ls"); return 0; } ``` 2) Compilamos o código seguinte, mudamos a sua propriedade para *owner* e tornámos-lo um programa Set-UID: ``` #include <stdio.h> #include <stdlib.h> int main() { printf("Programa malicioso\n"); system("chmod 777 ~/Downloads/FSI/some_file"); return 0; } ``` 3) Executamos o seguinte comando, para mudar a variável PATH na Bash: ``` $ export PATH=~/Downloads/FSI/:$PATH ``` Com este comando adicionamos o diretório ~/Downloads/FSI/ ao início PATH. 4) Ao executar o nosso programa do ponto 2 e executar o comando ls -l, para ver as permissões dos ficheiros, conseguimos ver que o programa alterou as propriedades do ficheiro. 5) O único obstáculo é que o sistema acabará por levar a uma chamada a /bin/dash, que possui contramedidas para esta situação, diminuindo as permissões do processo para as permissões de quem chama. Para isso mudamos o programa da shell para /bin/zsh, com o seguinte comando: ``` $ sudo ln -sf /bin/zsh /bin/sh ``` Os resultados estão nos *screenshots* seguintes: ![](https://i.imgur.com/kuEKgWw.png) ![](https://i.imgur.com/h914Iec.png) --- # CTF ### Vulnerabilidade encontrada Booster for Woocommerce, plugin do WordPress, é vulnerável a bypass de autenticação por e-mail até à versão 5.4.3, CVE-2021-34646. ### Utilizadores identificados: - Orval Sanford (ID?) - admin (ID: 1) ### Como executamos o ataques: Encontrámos um script no site exploit-db.com que automaticamente gerava tokens e verificava se "passavam" como login para um certo user, user esse sendo o de ID 1 no nosso caso. ### Versões de Software: - WordPress: 5.8.1 - WooCommerce: 5.7.1 - Booster for WooCommerce: 5.4.3

    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