lachlan2k / phatcrack

Modern web-based distributed hashcracking solution, built on hashcat
MIT License
109 stars 8 forks source link

Unable to delete project or task #37

Closed JSmith-Aura closed 1 month ago

JSmith-Aura commented 6 months ago
2024/04/04 21:52:05 /app/api/internal/db/project.go:263 SLOW SQL >= 200ms
[202.220ms] [rows:1] SELECT * FROM "hashlists" WHERE id = '<id>' AND "hashlists"."deleted_at" IS NULL ORDER BY "hashlists"."id" LIMIT 1
{"authenticated_username":"admin","level":"warning","log_type":"audit","msg":"Session started","remote_ip":"192.168.12.2","time":"2024-04-04T21:56:37Z"}

2024/04/04 21:57:04 /app/api/internal/db/project.go:263 SLOW SQL >= 200ms
[201.862ms] [rows:1] SELECT * FROM "hashlists" WHERE id = '<id>' AND "hashlists"."deleted_at" IS NULL ORDER BY "hashlists"."id" LIMIT 1

2024/04/04 21:57:17 /app/api/internal/db/job.go:333 ERROR: column attacks.hashlists_id does not exist (SQLSTATE 42703)
[9.408ms] [rows:0] SELECT "jobs"."id","jobs"."created_at","jobs"."updated_at","jobs"."deleted_at","jobs"."hashlist_version","jobs"."attack_id","jobs"."hashcat_params","jobs"."target_hashes","jobs"."hash_type","jobs"."assigned_agent_id" FROM "jobs" join attacks on attacks.id = jobs.attack_id WHERE attacks.hashlists_id = '<id>' AND "jobs"."deleted_at" IS NULL
{"URI":"/api/v1/hashlist/5a0099fe-ccb2-4152-bf85-a62c18d7e703","content_length":"","error":"ERROR: column attacks.hashlists_id does not exist (SQLSTATE 42703)","error_id":"f3e5050c-c893-4f20-944a-1805a42d957f","latency_ms":154,"level":"error","method":"DELETE","msg":"request error f3e5050c-c893-4f20-944a-1805a42d957f","remote_ip":"192.168.12.2","response_size":0,"status":500,"time":"2024-04-04T21:57:17Z","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36","user_id":"92580446-7aca-4f1f-95ef-8f160dbc9956","user_username":"admin"}

2024/04/04 21:57:19 /app/api/internal/db/job.go:333 ERROR: column attacks.hashlists_id does not exist (SQLSTATE 42703)
[0.337ms] [rows:0] SELECT "jobs"."id","jobs"."created_at","jobs"."updated_at","jobs"."deleted_at","jobs"."hashlist_version","jobs"."attack_id","jobs"."hashcat_params","jobs"."target_hashes","jobs"."hash_type","jobs"."assigned_agent_id" FROM "jobs" join attacks on attacks.id = jobs.attack_id WHERE attacks.hashlists_id = '<id>' AND "jobs"."deleted_at" IS NULL
{"URI":"/api/v1/hashlist/5a0099fe-ccb2-4152-bf85-a62c18d7e703","content_length":"","error":"ERROR: column attacks.hashlists_id does not exist (SQLSTATE 42703)","error_id":"0c7fcec8-afeb-42f6-9393-5227ce3d9514","latency_ms":132,"level":"error","method":"DELETE","msg":"request error 0c7fcec8-afeb-42f6-9393-5227ce3d9514","remote_ip":"192.168.12.2","response_size":0,"status":500,"time":"2024-04-04T21:57:19Z","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36","user_id":"92580446-7aca-4f1f-95ef-8f160dbc9956","user_username":"admin"}

2024/04/04 21:57:22 /app/api/internal/db/job.go:333 ERROR: column attacks.hashlists_id does not exist (SQLSTATE 42703)
[0.408ms] [rows:0] SELECT "jobs"."id","jobs"."created_at","jobs"."updated_at","jobs"."deleted_at","jobs"."hashlist_version","jobs"."attack_id","jobs"."hashcat_params","jobs"."target_hashes","jobs"."hash_type","jobs"."assigned_agent_id" FROM "jobs" join attacks on attacks.id = jobs.attack_id WHERE attacks.hashlists_id = '<id>' AND "jobs"."deleted_at" IS NULL
{"URI":"/api/v1/hashlist/5a0099fe-ccb2-4152-bf85-a62c18d7e703","content_length":"","error":"ERROR: column attacks.hashlists_id does not exist (SQLSTATE 42703)","error_id":"07c0f8d6-3c6c-446a-93a6-197849548966","latency_ms":156,"level":"error","method":"DELETE","msg":"request error 07c0f8d6-3c6c-446a-93a6-197849548966","remote_ip":"192.168.12.2","response_size":0,"status":500,"time":"2024-04-04T21:57:22Z","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36","user_id":"92580446-7aca-4f1f-95ef-8f160dbc9956","user_username":"admin"}

2024/04/04 21:57:46 /app/api/internal/db/job.go:348 SLOW SQL >= 200ms
[349.441ms] [rows:33] SELECT "jobs"."id","jobs"."created_at","jobs"."updated_at","jobs"."deleted_at","jobs"."hashlist_version","jobs"."attack_id","jobs"."hashcat_params","jobs"."target_hashes","jobs"."hash_type","jobs"."assigned_agent_id" FROM "jobs" join attacks on attacks.id = jobs.attack_id join hashlists on hashlists.id = attacks.hashlist_id WHERE hashlists.project_id = 'e373e6ca-89c2-442e-a6a3-38449a078de9' AND "jobs"."deleted_at" IS NULL

2024/04/04 21:57:46 /app/api/internal/db/db.go:30 ERROR: update or delete on table "projects" violates foreign key constraint "fk_projects_project_share" on table "project_shares" (SQLSTATE 23503)
[0.785ms] [rows:0] DELETE FROM "projects" WHERE "projects"."id" = 'e373e6ca-89c2-442e-a6a3-38449a078de9'
{"URI":"/api/v1/project/e373e6ca-89c2-442e-a6a3-38449a078de9","content_length":"","error":"ERROR: update or delete on table \"projects\" violates foreign key constraint \"fk_projects_project_share\" on table \"project_shares\" (SQLSTATE 23503)","error_id":"d0391bb3-bf4c-4edb-b397-0f6ddf408f48","latency_ms":350,"level":"error","method":"DELETE","msg":"request error d0391bb3-bf4c-4edb-b397-0f6ddf408f48","remote_ip":"192.168.12.2","response_size":0,"status":500,"time":"2024-04-04T21:57:46Z","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36","user_id":"92580446-7aca-4f1f-95ef-8f160dbc9956","user_username":"admin"}
lachlan2k commented 6 months ago

Looks like the cascade:ondelete was applied in the wrong place for project shares, and there was an issue with the query that looks for any jobs to stop.

Fix has been pushed and will be in 0.3.0.

Note: the following DB query will need to be run (because GORM doesn't want to auto-migrate constraints):

ALTER TABLE project_shares DROP CONSTRAINT fk_projects_project_share;

I'll put this in the release notes but leaving it here for now.