(Edit: I noticed I forgot to explicitly answer the main question. Yes, as far as I can tell it is grammatically correct.)
終わり is the so called 連用形(れんようけい)"connective form" of 終わる. This form does indeed serve as ます-stem, but it can also serve as a nominalization of the verb. In this case 終わり means "(the) end".
In fact, the 連用形 ("ます-stem") can be used to create nouns for most verbs. The resulting noun will have the meaning of "the act of ~ing", but it can often carry additional meanings as well:
切る "to cut" -> 切り "cutting (the action)", or more frequently: "cut (the result), "limit" (in an expansion of the original sense) etc.
The て-form can be used to connect the previous phrase with a following auxiliary verb, but it can also connect the previous phrase with a following phrase (and not neccessarily an auxiliary). This connection can be a temporal one / succession (AしてB: "Do A and then B"), or as it seems to be the case in your question, a rather conditional one (攻撃されて終わりだ: "If you get attacked, it's the end (= it's over)").
This conditional sense resembles the usage of the auxiliaries -たら or -ぇば.
I'm lacking the context but I'd guess an appropriate translation would be something like:
"If we get attacked while we're slugging around, we're done for!"
(ps This is my very first time posting on Stack Exchange so I hope I didn't mess anything up. Feel free to provide feedback, edit or correct me if neccessary.)