Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 0e48a71

Browse files
committed
Implement possibility to scan by sudoers.
- The remote scanning dialog got a "user is sudoer" checkbox. - Dry run can make use of sudo in connection with oscap-ssh. - The scanning procedure uses sudo invocation as part of the ssh command.
1 parent e2ca2e1 commit 0e48a71

File tree

6 files changed

+69
-10
lines changed

6 files changed

+69
-10
lines changed

include/OscapScannerRemoteSsh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class OscapScannerRemoteSsh : public OscapScannerBase
3636
OscapScannerRemoteSsh();
3737
virtual ~OscapScannerRemoteSsh();
3838

39+
void setUserIsSudoer(bool userIsSudoer);
3940
virtual void setTarget(const QString& target);
4041
virtual void setSession(ScanningSession* session);
4142

@@ -57,6 +58,7 @@ class OscapScannerRemoteSsh : public OscapScannerBase
5758
void removeRemoteDirectory(const QString& path, const QString& desc);
5859

5960
SshConnection mSshConnection;
61+
bool mUserIsSudoer;
6062
};
6163

6264
#endif

include/RemoteMachineComboBox.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class RemoteMachineComboBox : public QWidget
4444

4545
void setRecentMachineCount(unsigned int count);
4646
unsigned int getRecentMachineCount() const;
47+
bool userIsSudoer() const;
4748

4849
public slots:
4950
void notifyTargetUsed(const QString& target);
@@ -65,6 +66,7 @@ class RemoteMachineComboBox : public QWidget
6566

6667
QStringList mRecentTargets;
6768
QComboBox* mRecentComboBox;
69+
QCheckBox* mUserIsSudoer;
6870
};
6971

7072
#endif

src/MainWindow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ void MainWindow::scanAsync(ScannerMode scannerMode)
678678
// In the OscapScannerRemoteSsh class the port will be parsed out again...
679679
const QString target = mUI.localMachineRadioButton->isChecked() ?
680680
"localhost" : mUI.remoteMachineDetails->getTarget();
681+
const bool userIsSudoer = mUI.remoteMachineDetails->userIsSudoer();
681682

682683
bool fetchRemoteResources = mUI.fetchRemoteResourcesCheckbox->isChecked();
683684
try
@@ -689,7 +690,10 @@ void MainWindow::scanAsync(ScannerMode scannerMode)
689690
if (target == "localhost")
690691
mScanner = new OscapScannerLocal();
691692
else
693+
{
692694
mScanner = new OscapScannerRemoteSsh();
695+
((OscapScannerRemoteSsh *)mScanner)->setUserIsSudoer(userIsSudoer);
696+
}
693697

694698
mScanner->setTarget(target);
695699

src/OscapScannerRemoteSsh.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ extern "C"
3737

3838
OscapScannerRemoteSsh::OscapScannerRemoteSsh():
3939
OscapScannerBase(),
40-
mSshConnection(this)
40+
mSshConnection(this),
41+
mUserIsSudoer(false)
4142
{
4243
mSshConnection.setCancelRequestSource(&mCancelRequested);
4344
}
@@ -87,6 +88,11 @@ void OscapScannerRemoteSsh::setTarget(const QString& target)
8788
mSshConnection.setPort(port);
8889
}
8990

91+
void OscapScannerRemoteSsh::setUserIsSudoer(bool userIsSudoer)
92+
{
93+
mUserIsSudoer = userIsSudoer;
94+
}
95+
9096
void OscapScannerRemoteSsh::setSession(ScanningSession* session)
9197
{
9298
OscapScannerBase::setSession(session);
@@ -99,6 +105,10 @@ void OscapScannerRemoteSsh::setSession(ScanningSession* session)
99105
QStringList OscapScannerRemoteSsh::getCommandLineArgs() const
100106
{
101107
QStringList args("oscap-ssh");
108+
if (mUserIsSudoer)
109+
{
110+
args.append("--sudo");
111+
}
102112
args.append(mSshConnection.getTarget());
103113
args.append(QString::number(mSshConnection.getPort()));
104114

@@ -235,28 +245,34 @@ void OscapScannerRemoteSsh::evaluate()
235245

236246
if (mScannerMode == SM_OFFLINE_REMEDIATION)
237247
{
238-
args = buildOfflineRemediationArgs(inputFile,
248+
args.append(buildOfflineRemediationArgs(inputFile,
239249
resultFile,
240250
reportFile,
241-
arfFile);
251+
arfFile));
242252
}
243253
else
244254
{
245-
args = buildEvaluationArgs(inputFile,
255+
args.append(buildEvaluationArgs(inputFile,
246256
tailoringFile,
247257
resultFile,
248258
reportFile,
249259
arfFile,
250-
mScannerMode == SM_SCAN_ONLINE_REMEDIATION);
260+
mScannerMode == SM_SCAN_ONLINE_REMEDIATION));
251261
}
252262

253263
const QString sshCmd = args.join(" ");
254264

255265
emit infoMessage(QObject::tr("Starting the remote process..."));
256266

257267
QProcess process(this);
268+
QString sudo;
269+
if (mUserIsSudoer)
270+
{
271+
// tell sudo not to bother to read password from the terminal
272+
sudo = " sudo -n";
273+
}
258274

259-
process.start(SCAP_WORKBENCH_LOCAL_SSH_PATH, baseArgs + QStringList(QString("cd '%1'; " SCAP_WORKBENCH_REMOTE_OSCAP_PATH " %2").arg(workingDir).arg(sshCmd)));
275+
process.start(SCAP_WORKBENCH_LOCAL_SSH_PATH, baseArgs + QStringList(QString("cd '%1';" "%2 " SCAP_WORKBENCH_REMOTE_OSCAP_PATH " %3").arg(workingDir).arg(sudo).arg(sshCmd)));
260276
process.waitForStarted();
261277

262278
if (process.state() != QProcess::Running)

src/RemoteMachineComboBox.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ RemoteMachineComboBox::RemoteMachineComboBox(QWidget* parent):
4141
this, SLOT(updateHostPort(int))
4242
);
4343

44+
mUserIsSudoer = mUI.userIsSudoer;
45+
4446
setRecentMachineCount(5);
4547
syncFromQSettings();
4648

@@ -51,6 +53,11 @@ RemoteMachineComboBox::~RemoteMachineComboBox()
5153
delete mQSettings;
5254
}
5355

56+
bool RemoteMachineComboBox::userIsSudoer() const
57+
{
58+
return mUserIsSudoer->isChecked();
59+
}
60+
5461
QString RemoteMachineComboBox::getTarget() const
5562
{
5663
return QString("%1:%2").arg(mUI.host->text()).arg(mUI.port->value());

ui/RemoteMachineComboBox.ui

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>553</width>
10-
<height>29</height>
9+
<width>609</width>
10+
<height>42</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>RemoteMachineComboBox</string>
1515
</property>
1616
<layout class="QHBoxLayout" name="horizontalLayout">
17-
<property name="margin">
17+
<property name="leftMargin">
18+
<number>0</number>
19+
</property>
20+
<property name="topMargin">
21+
<number>0</number>
22+
</property>
23+
<property name="rightMargin">
24+
<number>0</number>
25+
</property>
26+
<property name="bottomMargin">
1827
<number>0</number>
1928
</property>
2029
<item>
@@ -73,8 +82,17 @@
7382
</item>
7483
<item>
7584
<widget class="QSpinBox" name="port">
85+
<property name="enabled">
86+
<bool>true</bool>
87+
</property>
88+
<property name="sizePolicy">
89+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
90+
<horstretch>0</horstretch>
91+
<verstretch>0</verstretch>
92+
</sizepolicy>
93+
</property>
7694
<property name="buttonSymbols">
77-
<enum>QAbstractSpinBox::UpDownArrows</enum>
95+
<enum>QAbstractSpinBox::NoButtons</enum>
7896
</property>
7997
<property name="minimum">
8098
<number>1</number>
@@ -87,6 +105,16 @@
87105
</property>
88106
</widget>
89107
</item>
108+
<item>
109+
<widget class="QCheckBox" name="userIsSudoer">
110+
<property name="toolTip">
111+
<string>Check if the remote user doesn't have root privileges, but they can perform administrative tasks using paswordless sudo.</string>
112+
</property>
113+
<property name="text">
114+
<string>user is sudoer</string>
115+
</property>
116+
</widget>
117+
</item>
90118
<item>
91119
<widget class="QComboBox" name="recentComboBox">
92120
<property name="sizePolicy">

0 commit comments

Comments
 (0)