General and Desktop
2022.09.18 15:50

QProcess 보안 권고 리뷰

조회 수 4979 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

올해 초에 Qt Project의 보안팀은 QProcess를 사용하여 전체 경로 없이 다른 응용 프로그램을 시작할 때 발생할 수 있는 보안관련 패치를 제공했었다.

여기서는 이 문제를 재현해보고 QProcess의 올바른 사용법을 알아본다. 아직 패치하지 않았거나 하기 어려운 개발자는 검토해 보시길.

테스트 환경:
Windows 11
MinGW 64-bit
Qt 5.15.2

이 문제는 PATH 환경 변수에서 목적의 실행 파일을 찾기 전에 먼저 해당 앱의 디렉토리를 검색하기 때문에 발생한다. 어떤 나쁜 마음을 먹은 공격자가 같은 이름의 악성 실행 파일을 앱과 같은 위치에 배치하고 정보를 가로 챌 수 있다.

다음과 같이 사용하는 경우가 문제의 원인이다.

QProcess p;
p.start("application", args);

예를 들어 애플리케이션이 시스템에 설치된 압축해제 프로그램을 사용하려고 한다. (bandizip 을 미리 설치해 두었다.)

#include <QCoreApplication>
#include <QProcess>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QStringList args;
    args.append("x"); // Unzip
    args.append("-p:Passw0rd"); // Password
    args.append("-o:" + a.applicationDirPath() + "/dest"); // Target folder
    args.append(a.applicationDirPath() + "/sample.zip"); // Archive

    QProcess p;
    p.start("bandizip", args);
    p.waitForFinished(-1);
}

압축파일의 경로 및 패스워드등이 전달된다. 압축파일이 문제없이 잘 풀린다.

하지만 이 문제를 노리고 데이터를 가로채는 프로그램을 앱과 같은 위치에 배치했다고 치자.

가짜 bandizip 구현

#include <QCoreApplication>
#include <QFile>
#include <QString>
#include <QDebug>
#include <QTextStream>

void write(const QString &filename, const QStringList &args)
{
    QFile file(filename);
    // Trying to open in WriteOnly and Text mode
    if(!file.open(QFile::WriteOnly |
                  QFile::Text))
    {
        qDebug() << " Could not open file for writing";
        return;
    }

    // To write text, we use operator<<(),
    // which is overloaded to take
    // a QTextStream on the left
    // and data types (including QString) on the right

    QTextStream out(&file);

    for(const auto &arg : args) {
        out << arg << "\n";
    }

    file.flush();
    file.close();
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    write("stealArgs.txt", a.arguments());

    return 0;
}

이 프로그램은 명령줄 옵션을 전달받고 파일에 쓰는 일을 한다.

이제 예제 앱을 실행하면 사용자가 기대하지 않은일이 벌어질 수 있다. 다음 이미지는 stealArgs.txt 파일의 내용이다.

stealArgs.png

패치하거나 최신버전을 사용하면 좋겠지만 당장어렵다면 애플리케이션의 전체 경로를 확인하여 이런 위험을 줄일 수 있다. 이 목적에 부합하는 QStandardPaths::findExecutable 를 사용하면 PATH 환경 변수를 검색하고 결과적으로 안전한 사용 경로를 제공받을 수 있다.

예제 코드는 다음과 같다.

#include <QCoreApplication>
#include <QProcess>
#include <QDebug>

#include <QStandardPaths>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    auto bandizipPath = QStandardPaths::findExecutable("bandizip");

    if( !bandizipPath.isEmpty() ){
        QStringList args;
        args.append("x"); // Unzip
        args.append("-p:Passw0rd"); // Password
        args.append("-o:" + a.applicationDirPath() + "/dest"); // Target folder
        args.append(a.applicationDirPath() + "/sample.zip"); // Archive

        QProcess p;
        p.start(bandizipPath, args);
        p.waitForFinished(-1);

        qDebug() << "finished";
    } else {
        qDebug() << "not found command.";
    }
}
TAG •

  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views436625
    read more
  2. Visual Studio Code용 Qt 확장팩

    Date2024.10.09 CategoryInstallation and Deployment Bymakersweb Views13534
    Read More
  3. Qt 응용프로그램에 Web 구성 요소를 표시 with Servo

    Date2024.04.27 CategoryGeneral and Desktop Bymakersweb Views14047
    Read More
  4. Qt Creator 에서 GitHub Copilot 사용하기

    Date2024.04.13 CategoryInstallation and Deployment Bymakersweb Views16523
    Read More
  5. No Image

    QtQuick 애플리케이션에 Rive 애니메이션 통합

    Date2024.03.31 CategoryQML and Qt Quick Bymakersweb Views9033
    Read More
  6. 클라우드용 Qt

    Date2024.01.16 CategoryInstallation and Deployment Bymakersweb Views7862
    Read More
  7. QRhi 에 대해서

    Date2023.12.29 CategoryQt 6 Bymakersweb Views9762
    Read More
  8. Android 애플리케이션 서명 구성

    Date2023.12.17 CategoryMobile and Embedded Bymakersweb Views8372
    Read More
  9. No Image

    QML의 사용자 정의 Image

    Date2023.09.17 CategoryC++ Class Bymakersweb Views11350
    Read More
  10. No Image

    Base64로 인코딩된 파일을 복원

    Date2023.08.06 CategoryC++ Class Bymakersweb Views14057
    Read More
  11. QML에서 D-Bus 통신

    Date2023.03.15 CategoryQML and Qt Quick Bymakersweb Views7229
    Read More
  12. Qt 하이브리드 애플리케이션(Hybrid App) 개발

    Date2023.02.08 CategoryGeneral and Desktop Bymakersweb Views8974
    Read More
  13. No Image

    Widgets(C++) 기반의 기본 스타일을 Dark 테마 및 Material 디자인 스타일로 바꾸기

    Date2023.01.28 CategoryGeneral and Desktop Bymakersweb Views12620
    Read More
  14. OpacityMask 예제

    Date2023.01.26 CategoryQML and Qt Quick Bymakersweb Views12158
    Read More
  15. QProcess 예제 (프로그램 재시작)

    Date2023.01.25 CategoryC++ Class Bymakersweb Views6836
    Read More
  16. 하드디스크 드라이브 여유 공간 계산

    Date2023.01.15 CategoryC++ Class Bymakersweb Views9218
    Read More
  17. No Image

    Qt Property(속성) 시스템

    Date2023.01.08 CategoryGeneral and Desktop Bymakersweb Views12928
    Read More
  18. VTK 를 사용해서 강력한 시각화(3D, Plotting, Chart)Qt 응용프로그램 개발하기

    Date2022.10.16 CategoryGeneral and Desktop Bymakersweb Views9433
    Read More
  19. QProcess 보안 권고 리뷰

    Date2022.09.18 CategoryGeneral and Desktop Bymakersweb Views4979
    Read More
  20. No Image

    QMake 프로젝트를 CMake 프로젝트로 변환 with qmake2cmake

    Date2022.09.17 CategoryInstallation and Deployment Bymakersweb Views5927
    Read More
  21. Qt Safe Renderer 개요

    Date2022.09.08 CategoryMobile and Embedded Bymakersweb Views13269
    Read More
Board Pagination Prev 1 2 3 4 5 9 Next
/ 9