Re: [oss-security] MitM attack against OpenSSH's VerifyHostKeyDNS-enabled client

Fórumok

https://seclists.org/oss-sec/2025/q1/144

 

kiemelnék egy replyt a topichoz, fellow HU colls

 

From: Buherátor
Date: Thu, 6 Mar 2025 22:15:08 +0100

Hi all,

I also gave this a shot and came up with this query that uses
data-flow tracking and also uses StackVariableReachability as
suggested by Jordy. The results match the original closely, and based
on my measurements it is more performant, esp. on larger codebases
(tested with OpenSSL):

```ql
import cpp
import semmle.code.cpp.controlflow.StackVariableReachability
import semmle.code.cpp.dataflow.new.DataFlow

// variable is not mentioned inside if
predicate notChildOfIf(Variable v, IfStmt i){
    not exists (VariableAccess a | a.getTarget()=v  and
i.getEnclosingStmt().getAChild*()=a.getEnclosingStmt())
}

// if leads to goto on its true path
predicate ifToGoto(IfStmt i, GotoStmt g){
    g.hasName() and
    i.getThen().getAChild*()=g
}

// Return statement accesses v
predicate isProperReturn(Variable v, ReturnStmt ret){
    exists(VariableAccess a | a.getTarget() = v and not a.isModified()
and a.getEnclosingStmt() = ret.getChildStmt*())
}

class InitToFaultyIfConfiguration extends StackVariableReachability {
    InitToFaultyIfConfiguration() { this = "InitToFaultyIfConfiguration" }

    override predicate isSource(ControlFlowNode node, StackVariable v) {
        // We are interested in all variable accesses
        // Note: Initializers are not VariableAccess!
        exists(VariableAccess ae | v = ae.getTarget() and
ae.isModified() and ae = node)

    }

    override predicate isSink(ControlFlowNode node, StackVariable v) {
        exists(ReturnStmt ret, GotoStmt goto, IfStmt i | node = i and
// Source is an IfStmt
               i.getEnclosingFunction() =
v.getAnAssignment().getEnclosingStmt().getEnclosingFunction() and //
IfStmt and StackVariable are in the same function
               isProperReturn(v,ret) and // Return statement accesses v
               notChildOfIf(v, i) and // return variable not part of
this if statement
               ifToGoto(i, goto) and // if leads to goto
               goto.getASuccessor+()=ret // goto leads to relevant return
        )
    }

    override predicate  isBarrier(ControlFlowNode node, StackVariable v) {
        exists(VariableAccess ae | v = ae.getTarget() and
ae.isModified() and ae = node)
    }
}

from ControlFlowNode sourceInit, ControlFlowNode sinkIf,
InitToFaultyIfConfiguration confInitIf, LocalVariable v, ReturnStmt
ret,
DataFlow::Node sinkRet, DataFlow::Node sourceDef
where confInitIf.reaches(sourceInit, v, sinkIf) and // A local
variable reaches a faulty if in the CFG
  isProperReturn(v, ret) and // the variable is used as part of the return
  sourceDef.asExpr() = v.getAnAssignment() and // we are looking for
data-flows from the return variable ...
  sinkRet.asExpr() = ret.getAChild() and // ... to the return statement
  DataFlow::localFlow(sourceDef, sinkRet) // we are only interested in
value-preserving, local data-flows
select sourceInit, sinkIf,
sinkIf.getLocation().getFile().getBaseName()+":"+sinkIf.getLocation().getStartLine()+":"+sinkIf.getLocation().getStartColumn()
```

I also wrote (much) about the development process to help tweaking the
query further:

  https://scrapco.de/blog/dreams-in-codeql-quest-for-the-perfect-goto.html

Code with additional data:

  https://github.com/v-p-b/codeql-verify-goto

I hope you'll find this useful. If you spot any errors or have other
questions/comments, please let me know!

Regards,

buherator

On Fri, 21 Feb 2025 at 18:57, Qualys Security Advisory <qsa () qualys com> wrote:


    Hi Jordy,

    On Fri, Feb 21, 2025 at 01:22:40PM +0100, Jordy Zomer wrote:

        Hope that's helpful, please reach out if you have any questions :)


    Woo-hoo, awesome work, thank you very much for sharing it! We are
    looking into it now (and learning from it).

    Thanks again! With best regards,

    --
    the Qualys Security Advisory team

Hozzászólások

A 'mire gondolt a költő' megfejtése pedig majd a kommentelőkre marad

"Nem akkor van baj amikor nincs baj, hanem amikor van!"
Népi bölcsesség

Jó, akkor tömörítsünk:

"A Qualys Threat Research Unit (TRU) 2025. február 21-én közzétett két OpenSSH sebezhetőséget, melyek egy tipikus hibakezelési mintára vezethetők vissza. A TRU megosztott egy alapvető CodeQL lekérdezést is, és felhívást intézett a közösséghez annak optimalizálására. A cikk szerzője elfogadta ezt a kihívást, és részletesen elemzi a TRU eredeti lekérdezését, majd bemutat egy optimalizált megoldást, amely hatékonyabban azonosítja a potenciális hibákat az OpenSSH kódbázisában."

 

Az újságírás egy szakma, de úgy látszik lassan már a kommentelés is

"Nem akkor van baj amikor nincs baj, hanem amikor van!"
Népi bölcsesség

Nice!

OFFTOPIC
Szégyen és gyalázat a magyarokra nézve, hogy egy ilyen kaliberű és képességű szakember kénytelen volt németbe emigrálni, mert idehaza nem hagyták boldogulni.