Skip to content

Commit c29e971

Browse files
committed
integrate exploits with nvip
1 parent c4844dd commit c29e971

8 files changed

+147
-10
lines changed

.env-local

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
APP_PORT=3000
2+
DATABASE_HOST=localhost
3+
DATABASE_PORT=3306
4+
DATABASE_USER=root
5+
DATABASE_PASSWORD=root
6+
DATABASE_NAME=nvip
7+
SSVC_API_URL=http://54.147.187.238:5000/ssvc

src/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { VulnerabilityModule } from './vulnerability/vulnerability.module';
3232
import { CveModule } from './cve/cve.module';
3333
import { SsvcModule } from './ssvc/ssvc.module';
3434
import { ConfigModule } from '@nestjs/config';
35+
import { ExploitsModule } from './exploits/exploits.module';
3536
@Module({
3637
imports: [
3738
ConfigModule.forRoot({
@@ -75,6 +76,7 @@ import { ConfigModule } from '@nestjs/config';
7576
VulnerabilityModule,
7677
CveModule,
7778
SsvcModule,
79+
ExploitsModule,
7880
],
7981
controllers: [AppController],
8082
providers: [AppService],

src/cve/cve.service.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ export class CveService {
7272
async getCveExploits(cveId: string) {
7373
const exploits = await this.exploitRepository.find({
7474
where: {
75-
vulnerability: {
76-
cveId: cveId,
77-
},
75+
cveId: cveId,
7876
},
7977
});
80-
return exploits;
78+
return exploits
8179
}
8280

8381
async getCveRawDescriptions(cveId: string) {

src/entities/exploit.entity.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ export class Exploit {
4040
@Column({ name: 'download_failed' })
4141
downloadFailed: boolean;
4242

43-
@ManyToOne(() => Vulnerability, (vulnerability) => vulnerability.exploits)
44-
@JoinColumn({ name: 'cve_id' , referencedColumnName: 'cveId'})
45-
vulnerability: Vulnerability;
43+
@Column()
44+
cveId: string;
4645

4746
@Column()
4847
sourceUrl: string;
4948

49+
@Column({ type: 'text', nullable: true,name:'file_content' })
50+
fileContent: string;
51+
5052
@Column({ name: 'ignore' })
5153
ignore: boolean;
5254

src/entities/vulnerability.entity.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export class Vulnerability {
3030
@CreateDateColumn()
3131
createdDate: Date;
3232

33-
// Assuming Exploit, Timegap, PatchCommit, Fix, RawDescription, SSVC, and VulnerabilityVersion are also TypeORM entities
34-
@OneToMany(() => Exploit, (exploit) => exploit.vulnerability)
35-
exploits: Exploit[];
33+
3634

3735
@OneToMany(() => Timegap, (timegap) => timegap.vulnerability)
3836
timegaps: Timegap[];

src/exploits/exploits.controller.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Body,
6+
Patch,
7+
Param,
8+
Delete,
9+
} from '@nestjs/common';
10+
import { ExploitsService } from './exploits.service';
11+
12+
13+
@Controller('exploits')
14+
export class ExploitsController {
15+
constructor(private readonly exploitsService: ExploitsService) {}
16+
17+
@Post()
18+
create(@Body() createExploitDto: any) {
19+
console.log(`${createExploitDto.page}:${createExploitDto.source_url}`)
20+
return this.exploitsService.create(createExploitDto);
21+
}
22+
23+
@Get()
24+
findAll() {
25+
return this.exploitsService.findAll();
26+
}
27+
28+
@Get(':id')
29+
findOne(@Param('id') id: string) {
30+
return this.exploitsService.findOne(+id);
31+
}
32+
33+
@Patch(':id')
34+
update(
35+
@Param('id') id: string,
36+
@Body() updateExploitDto: any,
37+
) {
38+
return this.exploitsService.update(+id, updateExploitDto);
39+
}
40+
41+
@Delete(':id')
42+
remove(@Param('id') id: string) {
43+
return this.exploitsService.remove(+id);
44+
}
45+
}

src/exploits/exploits.module.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Module } from '@nestjs/common';
2+
import { ExploitsService } from './exploits.service';
3+
import { ExploitsController } from './exploits.controller';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
import { Exploit, Vulnerability } from 'src/entities';
6+
7+
@Module({
8+
imports:[
9+
TypeOrmModule.forFeature([
10+
Vulnerability,
11+
Exploit,
12+
]),
13+
],
14+
controllers: [ExploitsController],
15+
providers: [ExploitsService],
16+
})
17+
export class ExploitsModule {}

src/exploits/exploits.service.ts

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { InjectRepository } from '@nestjs/typeorm';
3+
import { Exploit, Vulnerability } from 'src/entities';
4+
import { Repository } from 'typeorm';
5+
6+
@Injectable()
7+
export class ExploitsService {
8+
constructor(
9+
@InjectRepository(Vulnerability)
10+
private vulnRepository: Repository<Vulnerability>,
11+
@InjectRepository(Exploit)
12+
private exploitRepository: Repository<Exploit>,
13+
) {}
14+
15+
async findVulnerability(cveId:string){
16+
const vulnerability=await this.vulnRepository.findOne({
17+
where:{
18+
cveId:cveId
19+
}
20+
})
21+
return vulnerability;
22+
}
23+
24+
async create(createExploitDto: any) {
25+
26+
var cves = createExploitDto.cve_id.split(',');
27+
for (var cve of cves){
28+
const currentCve=cve.trim()
29+
console.log(currentCve);
30+
const exploit =this.exploitRepository.create({
31+
cveId:currentCve,
32+
name:createExploitDto.name,
33+
source:createExploitDto.source,
34+
sourceUrl:createExploitDto.source_url,
35+
description:createExploitDto.description,
36+
fileContent:createExploitDto.file_content?createExploitDto.file_content:null,
37+
isRepo:createExploitDto.is_repo,
38+
datePublished:createExploitDto.date_published,
39+
exampleFile:createExploitDto.file_name,
40+
author:createExploitDto.author,
41+
downloadFailed:false,
42+
ignore:false,
43+
fixed:false,
44+
dateCreated:null
45+
});
46+
await this.exploitRepository.save(exploit)
47+
48+
}
49+
return 'This action adds a new exploit';
50+
51+
}
52+
53+
findAll() {
54+
return `This action returns all exploits`;
55+
}
56+
57+
findOne(id: number) {
58+
return `This action returns a #${id} exploit`;
59+
}
60+
61+
update(id: number, updateExploitDto: any) {
62+
return `This action updates a #${id} exploit`;
63+
}
64+
65+
remove(id: number) {
66+
return `This action removes a #${id} exploit`;
67+
}
68+
}

0 commit comments

Comments
 (0)