use crate::{
modules::{HttpModule, Module, ModuleName, ModuleVersion},
report::{Finding, ModuleResult, Severity},
Error,
};
use async_trait::async_trait;
use reqwest::Client;
pub struct GitlabOpenRegistrations {}
impl GitlabOpenRegistrations {
pub fn new() -> Self {
GitlabOpenRegistrations {}
}
}
impl Module for GitlabOpenRegistrations {
fn name(&self) -> ModuleName {
ModuleName::HttpGitlabOpenRegistration
}
fn description(&self) -> String {
String::from("Check if the GitLab instance is open to registrations")
}
fn version(&self) -> ModuleVersion {
ModuleVersion(1, 0, 0)
}
fn is_aggressive(&self) -> bool {
false
}
fn severity(&self) -> Severity {
Severity::High
}
}
#[async_trait]
impl HttpModule for GitlabOpenRegistrations {
async fn scan(&self, http_client: &Client, endpoint: &str) -> Result<Option<Finding>, Error> {
let url = format!("{}", &endpoint);
let res = http_client.get(&url).send().await?;
if !res.status().is_success() {
return Ok(None);
}
let body = res.text().await?;
if body.contains("This is a self-managed instance of GitLab") && body.contains("Register") {
return Ok(Some(Finding {
module: self.name(),
module_version: self.version(),
severity: self.severity(),
result: ModuleResult::Url(url),
}));
}
Ok(None)
}
}