Giter Club home page Giter Club logo

Comments (2)

security-curious avatar security-curious commented on September 16, 2024 2

Played with this a bit and you are correct. While a lack of closing comment may make it impossible in some languages other Ruby-specific features make it possible in Ruby. In #9 we talked about an identifier having control codes. If we make a variable entirely control codes it becomes invisible. What I wanted to do was this:

<ctrl-codes>; return # <ctrl-codes>

Basically put two statements on the same line. One that is useless just to start the control codes. End the statement and then put my return followed by the comment and control codes so I can move my useless statement to the comment. This didn't quite work out because my local variable was not initialized causing an error. Therefore I assigned it one of the values that came into the function. Still a useless statement but it makes it run:

<ctrl-codes> = amount; return # <ctrl-codes>

The ; really stands out but we can use the logical and operator as an alternate method of joining two statements on the line to give the comment a more natural token. Final result:

$bank = { 'alice' => 100 }

def subtract_funds account, amount
  ⁧⁦ = amount and return # ⁩⁦# Subtract from acct the value⁩⁩
  $bank[account] -= amount
end

subtract_funds 'alice', 50

If it wasn't for the syntax highlighting it would be a pretty convincing early return. We can do a similar trick for comment out:

is_admin = false
⁧⁦ = true; #⁩⁦if is_admin       # Begin block if is_admin⁩⁩
  puts 'You are an admin'
⁧⁦ = true;   #⁩⁦end               # End block if is_admin ⁩⁩

To answer my own question, I think the general answer is languages without a closing comment token are safe from these two strategies but other language characteristics may enable them again. Going to go ahead and close this issue since I think it's fairly well explored.

from trojan-source.

nickboucher avatar nickboucher commented on September 16, 2024

This is a fantastic topic, and my inclination is to say the answer is "yes". As you imply, the stretched string technique should work as long as the interpreter supports the Unicode tokens (although I haven't tested anything in Ruby).

That said, there may be other (perhaps Ruby-specific ways) of implementing early-return and commenting-out attacks. If so, I'd be interested to see what they and if they generalize to other language settings.

Let's leave this issue open and see if anyone has any Ruby-specific suggestions for techniques that could implement these two attacks.

from trojan-source.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.